Description
Godot version
v4.2.beta1.mono.official [b137180]
System information
Godot v4.2.beta1.mono - Windows 10.0.19045 - Vulkan (Forward+) - dedicated NVIDIA GeForce RTX 3090 (NVIDIA; 31.0.15.3713) - 13th Gen Intel(R) Core(TM) i7-13700K (24 Threads)
Issue description
When QueueFree or Free is called on a node in C#, a few issues occur:
The Node is disposed by the time TreeExiting is emitted
_ExitTree is never called
_Notification never receives NOTIFICATION_EXIT_TREE
This does not occur when removing the node with RemoveChild, or when freeing the node in GDScript
Steps to reproduce
The actual reproduction steps are pretty simple. Just call QueueFree or Free on a node.
I've attached a minimal project that can be run and gives more information. Here is the output from running that project:
Each script has this structure, the only difference being one of them calls GetParent().RemoveChild(this)
instead of QueueFree()
in the _Process()
method:
[Signal] public delegate void InitializedEventHandler();
public override void _Ready()
{
Print("Starting C# QueueFree Example...");
TreeExiting += Cleanup;
Initialized += () => Print("init");
}
public override void _Process(double delta) => QueueFree();
public override void _Notification(int what)
{
if (what == (int)NotificationExitTree)
Print("Notify Exit");
}
public override void _ExitTree() => Print("_exit_tree");
public void Cleanup()
{
Print("cleanup");
try
{
EmitSignal(SignalName.Initialized);
}
catch (Exception ex)
{
PrintErr(ex.Message);
}
}