godotengine / godotengine/godot

When initializing a packed scene, if the packed scene root has a script that chooses a parent on _init(), causes errors and will cause segfault.

Open
#97,525 4 comments 0 reactions 0 assignees View on GitHub
bug confirmed crash topic:core
Dominant language
C++
Stars
117k
Forks
26.8k
PR merge metrics
PR metrics pending

Description

### Tested versions

4.3.1.rc

### System information

Ubuntu 22.04.4 LTS 64-bit

### Issue description

I have a class_name Foo that chooses its parent via a method of a Autoload/Singleton. Foo.new() works fine. However, if I have a load a packed scene whose root is Foo (load("foo.tscn")), trying to remove the child from the parent creates a "Children name does not match parent name in hashtable" error.

Closing the window via the [x] button / quit via the system context menu causes a segfault.

Freeing the object will silently crash.

```
ERROR: Children name does not match parent name in hashtable, this is a bug.
at: remove_child (scene/main/node.cpp:1625)
Orphans:
ERROR: Parameter "get_viewport()" is null.
at: _notification (scene/main/node.cpp:144)
ERROR: Children name does not match parent name in hashtable, this is a bug.
at: remove_child (scene/main/node.cpp:1625)
ERROR: Condition "data.parent" is true.
at: ~Node (scene/main/node.cpp:3847)

================================================================
handle_crash: Program crashed with signal 11
Engine version: Godot Engine v4.3.1.rc.custom_build (ff9bc0422349219b337b015643544a0454d4a7ee)
Dumping the backtrace. Please include this when reporting the bug to the project developer.
[1] /lib/x86_64-linux-gnu/libc.so.6(+0x42520) [0x7c8191a42520] (??:0)
[2] Object::notification(int, bool) (/home/leonard/Git/godot/core/object/object.cpp:884)
[3] Object::_predelete() (/home/leonard/Git/godot/core/object/object.cpp:199)
[4] predelete_handler(Object*) (/home/leonard/Git/godot/core/object/object.cpp:2125)
[5] void memdelete(Node*) (/home/leonard/Git/godot/./core/os/memory.h:112)
[6] Node::_notification(int) (/home/leonard/Git/godot/scene/main/node.cpp:245)
[7] Node::_notificationv(int, bool) (/home/leonard/Git/godot/./scene/main/node.h:50 (discriminator 14))
[8] Node3D::_notificationv(int, bool) (/home/leonard/Git/godot/./scene/3d/node_3d.h:52)
[9] Object::notification(int, bool) (/home/leonard/Git/godot/core/object/object.cpp:890)
[10] Object::_predelete() (/home/leonard/Git/godot/core/object/object.cpp:199)
[11] predelete_handler(Object*) (/home/leonard/Git/godot/core/object/object.cpp:2125)
[12] void memdelete(Node*) (/home/leonard/Git/godot/./core/os/memory.h:112)
[13] Node::_notification(int) (/home/leonard/Git/godot/scene/main/node.cpp:245)
[14] Node::_notificationv(int, bool) (/home/leonard/Git/godot/./scene/main/node.h:50 (discriminator 14))
[15] CanvasItem::_notificationv(int, bool) (/home/leonard/Git/godot/./scene/main/canvas_item.h:45)
[16] Control::_notificationv(int, bool) (/home/leonard/Git/godot/./scene/gui/control.h:48)
[17] Object::notification(int, bool) (/home/leonard/Git/godot/core/object/object.cpp:890)
[18] Object::_predelete() (/home/leonard/Git/godot/core/object/object.cpp:199)
[19] predelete_handler(Object*) (/home/leonard/Git/godot/core/object/object.cpp:2125)
[20] void memdelete(Node*) (/home/leonard/Git/godot/./core/os/memory.h:112)
[21] Node::_notification(int) (/home/leonard/Git/godot/scene/main/node.cpp:245)
[22] Node::_notificationv(int, bool) (/home/leonard/Git/godot/./scene/main/node.h:50 (discriminator 14))
[23] Viewport::_notificationv(int, bool) (/home/leonard/Git/godot/./scene/main/viewport.h:95)
[24] Window::_notificationv(int, bool) (/home/leonard/Git/godot/./scene/main/window.h:44)
[25] Object::notification(int, bool) (/home/leonard/Git/godot/core/object/object.cpp:890)
[26] Object::_predelete() (/home/leonard/Git/godot/core/object/object.cpp:199)
[27] predelete_handler(Object*) (/home/leonard/Git/godot/core/object/object.cpp:2125)
[28] void memdelete(Window*) (/home/leonard/Git/godot/./core/os/memory.h:112)
[29] SceneTree::finalize() (/home/leonard/Git/godot/scene/main/scene_tree.cpp:645)
[30] OS_LinuxBSD::run() (/home/leonard/Git/godot/platform/linuxbsd/os_linuxbsd.cpp:967)
[31] /home/leonard/Git/godot/bin/godot.linuxbsd.editor.dev.x86_64(main+0x190) [0x5f09e01af539] (/home/leonard/Git/godot/platform/linuxbsd/godot_linuxbsd.cpp:85)
[32] /lib/x86_64-linux-gnu/libc.so.6(+0x29d90) [0x7c8191a29d90] (??:0)
[33] /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0x80) [0x7c8191a29e40] (??:0)
[34] /home/leonard/Git/godot/bin/godot.linuxbsd.editor.dev.x86_64(_start+0x25) [0x5f09e01af2e5] (??:?)
-- END OF BACKTRACE --
================================================================
```

### Steps to reproduce

I have attached an MRP.

The class_name Foo accesses a singleton to be able to be added to the tree.
The main script will load a packedscene of Foo on ready, which is when the issues should start.

### Minimal reproduction project (MRP)

[parent_crash.zip](https://github.com/user-attachments/files/17159971/parent_crash.zip)

Contributor guide

Open the contributing guide

Research direction

Start by running the attached parent_crash.zip minimal reproduction and tracing the packed-scene initialization path into scene/main/node.cpp, especially remove_child and the Node destruction notifications shown in the backtrace. Check the shutdown path through scene/main/scene_tree.cpp. Done means loading and freeing the packed scene no longer produces orphan or parent-hashtable errors and does not segfault.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, godot
Domain
game-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.