queue_free() in NEW setget in Godot 4.0 crashes game

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By sporx13

I have this line of code in new setget and it crashes game when hp gets below 0. Any ideas?

var hp: int:
	get: return hp
		hp = value
		if hp <= 0:
			get_parent().get_node("ProgressBar").value = hp

Does it crash, or just exit?
Have you debugged whether it’s the “get_parent” that’s doing it, or the Globals.update_money?

Does update_money in any way end changing hp? if so then you might get an infinite loop and godot might crash for that reason.

does get_parent return what you think it does? are you accidentally queue_free-ing the game?

Does the crash give you any errors? one way to test this is to run godot in a command line (for windows it’s godot.exe -e) That way when it exits you can see if it told you what the errors were

rossunger | 2022-01-27 22:06

I suspect rossunger is spot on and you’re accidentally queue_freeing the base viewport. That’ll kill your game pretty sharpish.

DaddyMonster | 2022-01-27 23:29

Looks like I gave you guys not enough information. Problem was in Tween. I have tween_property on loop and I create it under get_tree() (not under that node). That’s why when I queue_free() that node. Tween just loses target and game freeze.

There are 2 solutions for now (28.01.2022).

  1. Kill tween before queue_free() it’s target node. (that is what I’ve done in screenshot)
  2. Create tween under node that you are going to queue_free(). That way it will be killed with it.

sporx13 | 2022-01-28 07:28