godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
89.15k stars 20.21k forks source link

[4a9] App Crashes on exit when Node is in memory but not attached to the Scene Tree #61703

Open dev-inigmas opened 2 years ago

dev-inigmas commented 2 years ago

Godot version

v4.0.alpha9.official

System information

Ubuntu 20.04.4 LTS, Vulkan API 1.2.131 - Using Vulkan Device #0: AMD - AMD RADV NAVI10

Issue description

Expected App to exit cleanly. Got this:

handle_crash: Program crashed with signal 11
Engine version: Godot Engine v4.0.alpha9.official (fc18891dbceace03c3867ac26c15b79cfbc673df)
Dumping the backtrace. Please include this when reporting the bug on https://github.com/godotengine/godot/issues
[1] /lib/x86_64-linux-gnu/libc.so.6(+0x43090) [0x7f77e51e7090] (??:0)
[2] /home/user/bin/godot4() [0x3b50f8b] (??:0)
[3] /home/user/bin/godot4() [0x3be6102] (??:0)
[4] /home/user/bin/godot4() [0x3bd9121] (??:0)
[5] /home/user/bin/godot4() [0x37694eb] (??:0)
[6] /home/user/bin/godot4() [0xdc5971] (??:0)
[7] /home/user/bin/godot4() [0xda9b4a] (??:0)
[8] /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf3) [0x7f77e51c8083] (??:0)
[9] /home/user/bin/godot4() [0xdc3aae] (??:0)
-- END OF BACKTRACE --
================================================================

I don't recall this happening in Alpha 8.

Steps to reproduce


# Main.gd attached to Main.tscn
extends Node

# LoadScreen is a ColorRect with a ProgressBar, vars, and logic
@onready var load_screen: LoadScreen = $LoadScreen

# At some point, the scene is loaded. So "load_screen" is removed from the SceneTree.
func _change_scene() -> void:
  var new_scene: Node = ResourceLoader.load_threaded_get(loaded_path).instantiate()
  loaded_path = ""

  current_scene = new_scene
  add_child(current_scene)
  remove_child(load_screen)

# Called when pushing a "quit" button in the UI. Uncommenting "load_screen.free()" prevents crash.
func _on_quit2desktop() -> void:
  #load_screen.free()
  get_tree().quit(0)

Minimal reproduction project

No response

dev-inigmas commented 2 years ago

In addition to freeing load_screen in the "quit" Callback. Leaving load_screen in the SceneTree and calling show and hide as needed is another workaround to preventing the App from cashing on exit.

qarmin commented 2 years ago

Please provide minimal project, without it there is no way to reproduce crash and fix it

dev-inigmas commented 2 years ago

unattached_node.zip

As minimal as I could get it while reproducing the crash. signal 11 crash on exit.