godot icon indicating copy to clipboard operation
godot copied to clipboard

"Internal Script Error! - opcode #0 (report please)" when saving a script while a Timer is running in the project (due to live script reloading)

Open Gustavolucas864 opened this issue 5 years ago • 7 comments

error description in debugger: E 0:01:39.393 call: Condition ' (ip + 5) > _code_size ' is true. Breaking..: <C++ Source> modules/gdscript/gdscript_function.cpp:447 @ call() <Stack Trace> inimigo_ranged_1.gd:30 @ _on_cadencia_tiro_timeout()

Godot version: 3.2.1 stable_win64

OS/device including version: MX150, GLES2

Issue description: idk, im working in other script when my game simply crashed...

Steps to reproduce: idk

Minimal reproduction project: i will send a .txt with script that crashed (ps. im brazilian, almost whole the words of my variables and functions are in pt-br)

extends KinematicBody2D

var alvo = self #self apenas para n ficar Null e poder dar algum erro
var velocidade = 75 #velocidade com q o inimigo se movimenta
var pode_atirar = true #cadenciador de ataques
var cadencia_ataques = 2.0 #tempo entre cada ataque
export var dano = 10 #dano infligido por esse inimigo
var pre_projetil = preload("res://scenes/projeteis/projetil_inmigo_ranged_1.tscn")

signal morreu


func _ready():
	$"hit_box/CollisionShape2D".disabled = false #ativa a hitbox do inimigo


func _process(delta):
	alvo = self.get_parent().get_node("player") #pega o jogador como alvo
	if (alvo.global_position - self.global_position).length() >= 600: #distancia entre o jogador e o inimigo
		movimento_avanco() #avanca pra cima do jogador
	else:
		tiro() #atira no jogador


func movimento_avanco():
	var direcao_player = (alvo.global_position - self.global_position).normalized()
	move_and_slide(direcao_player * velocidade)


func tiro():
	#it was in this function that the error occurred...
	if pode_atirar: #pode_atirar é uma variavel de controle da cadencia
		pode_atirar = false
		$"AnimationPlayer".play("aviso_ataque_piscada")
		yield($"AnimationPlayer", "animation_finished")
		
		$"AnimationPlayer".play("tiro")
		var mira = alvo.global_position + Vector2(0, -12) #+altura do sprite, pra mirar pro meio da hitbox do jogador
		$"arma".look_at(mira)
		
		var projetil = pre_projetil.instance()
		projetil.vetor = Vector2(cos($"arma".global_rotation), sin($"arma".global_rotation)) #vetor é a direcao que o projetil ira seguir
		projetil.global_rotation = $"arma".global_rotation
		projetil.global_position = $"arma/Position2D".global_position
		self.get_parent().add_child(projetil) 
		
		yield($"AnimationPlayer", "animation_finished") #espera a animacao do tiro terminar
		$"cadencia_tiro".start(cadencia_ataques) #inicia o timer da cadencia


func _on_cadencia_tiro_timeout():
	pode_atirar = true #torna possivel atirar outra vez


func inimigo_acertado():
	#print("inimigo acertado")
	pass

func inimigo_morto():
	#print("inimigo morto")
	
	emit_signal("morreu")
	self.queue_free()

Gustavolucas864 avatar Sep 28 '20 03:09 Gustavolucas864

So I randomly hit upon this error when I resized a Control and saved the scene while the project was running. I noticed that the error in question happened on a yield call and I was able to reproduce it.

  • Create any scene with any node and attach this script:
extends Node

func _ready():
	while true:
		yield(get_tree().create_timer(1.0), "timeout")
		print("blah")
  • Run the project
  • While the project is running, save the scene again (modifying it is not necessary). You likely will get Internal Script Error! - opcode #0 (report please) or a crash.

I'm guessing it's a use-after-free.

reload-use-after-free.zip

Demindiro avatar Jan 15 '21 00:01 Demindiro

this happened with me too in 3.4 beta 6 over linux

image

related to the yield too!

nonunknown avatar Oct 18 '21 22:10 nonunknown

This comes back at 3.5 rc4.

hapenia avatar Jun 25 '22 06:06 hapenia

on 4.2.dev4 ...

E 0:01:41:0193   root.gd:65 @ _on_context_button_button_up(): Condition ' (ip + 8) > _code_size ' is true. Breaking..:
  <C++ Source>   modules/gdscript/gdscript_vm.cpp:2834 @ call()
  <Stack Trace>  root.gd:65 @ _on_context_button_button_up()

the code is just...

await get_tree().create_timer(5).timeout

alanenggb avatar Sep 24 '23 23:09 alanenggb

I was able to reproduce this with a trivial example.

Create a Sprite2D. Attach this script. While the game is running, edit the script (for example, change the print("a") to pass) and then save the script.

The next time the time fires you'll get an error. I've found the error can vary. For me, I just got: Error calling utility function "()": 1

########### script

extends Sprite2D

func _ready(): doStuff()

func _process(delta): print("a")

func doStuff(): for a in range(1, 30): await get_tree().create_timer(3).timeout print("awaited done " + str(a))

aspragg avatar Dec 15 '23 04:12 aspragg

same with me but error code is different. If necessary i open new issue post, sorry comments are in Portuguese-BR. Seems this error occours in line 31 in await get_tree().create_timer(0.5).timeout

error description in debugger:

E 0:05:03:0033   PersonMainScript.gd:31 @ @implicit_new(): Condition ' (ip + 4) > _code_size ' is true. Breaking..:
  <Origem C++>   modules/gdscript/gdscript_vm.cpp:3272 @ call()
  <Rastreamento de Pilha>PersonMainScript.gd:31 @ @implicit_new()

Internal script error! Opcode: 101 (please report).

Godot version: 4.2.1.Stable

error occours in this script

extends Person


func _ready():
	if !is_player:
		NavMeshAgent.velocity_computed.connect(Callable(_on_velocity_computed))
		$SophiaSkin/AnimationTree.active = true

func _process(_delta):
	# adicionando o personagem na lista global caso seja um trabalhador e definindo como nao jogador
	if actual_profession != Profession.PLAYER:
		is_player = false
		CameraNode.current = false
		if !GlobalWorkers.workers_object_list.has(self):
			GlobalWorkers.workers_object_list.append(self)

	else:
		#definindo o personagem como o jogador e habilitando os controles.
		is_player = true
		CameraNode.current = true
		"""
		Habilitando o movimento caso seja o jogador, verificar a classe Movement
		para mais detalhes do porque a fisica estar desabilitada e ativamos a fisica
		"""
	
	set_physics_process(true)
	if NavMeshAgent.is_navigation_finished():
		if work_module.work_spot_is_valid():
			visao.look_at(work_module.initial_work_pos)
			#TODO ajustes para testes remover futuramente!!!
			await get_tree().create_timer(0.5).timeout ## <--------------------------------- ERRORS HAPPENS HERE!!
			if !delivering:
				
				work_module.delivery_work_object()
				print("delivering object")
				delivering = true
			
	pass
#TODO variáveis temporárias
var delivering = false
var moved:bool = false		
func _physics_process(delta):
	
	if not is_on_floor():
		velocity.y -= gravity * delta
		
	if is_player: # este corpo faz o jogador ter permissao para se mover
		process_player_input(delta)
		"""
		necessário fornecer o delta, esta função é herdada da classe movment
		para o movimento funcionar é necessário ativar o physics_process() em uma
		função _ready() ou _process()
		"""
		
	else:#neste bloco o controle do jogador é desabilitado e o personagem se torna um NPC
		move_with_navmesh(delta)
		

on 4.2.dev4 ...

E 0:01:41:0193   root.gd:65 @ _on_context_button_button_up(): Condition ' (ip + 8) > _code_size ' is true. Breaking..:
  <C++ Source>   modules/gdscript/gdscript_vm.cpp:2834 @ call()
  <Stack Trace>  root.gd:65 @ _on_context_button_button_up()

the code is just...

await get_tree().create_timer(5).timeout

azediawan avatar Mar 03 '24 17:03 azediawan

This still happens in 4.2.1; it seems to happen whenever you create a timer with get_tree().create_timer and immediately await the timeout signal and then live-reload the script.
this is the line of code that adds the break opcode: https://github.com/godotengine/godot/blob/b09f793f564a6c95dc76acc654b390e68441bd01/modules/gdscript/gdscript_vm.cpp#L2448

Protowalker avatar Mar 24 '24 16:03 Protowalker

I get this randomly when doing ResourceLoader.load.

Edit: It might only be happening with the third argument of , ResourceLoader.CACHE_MODE_IGNORE_DEEP.

This is 4.4.rc3

Points to this line:

https://github.com/godotengine/godot/blob/15ff450680a40391aabbffde0a57ead2cd84db56/modules/gdscript/gdscript_vm.cpp#L717

halcyon1234 avatar Mar 02 '25 00:03 halcyon1234

This has been fixed by https://github.com/godotengine/godot/pull/102521 for 4.5. @lawnjelly since this issue was originally reported against 3.x, is there any interest in backporting the fix? Otherwise we can close this issue.

HolonProduction avatar Aug 08 '25 18:08 HolonProduction

I've added this to the 3.x issues, will try and take a look whether it can be backported when I get a moment, it looked fairly simple. 👍

As an aside, issues opened on 3.x that represent bugs that are still present should not be closed.

Some have been "kidnapped" and moved to 4.x milestone, but if closed in 4.x, then it's appropriate to just change milestone back to 3.x and leave open (I'll see it when searching by milestone).

Or ping me as you have done here (or in RC) if not sure. 👍

lawnjelly avatar Aug 12 '25 07:08 lawnjelly