Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash when removing last child node from a GraphNode #65557

Closed
caseyjoy opened this issue Sep 9, 2022 · 2 comments
Closed

Crash when removing last child node from a GraphNode #65557

caseyjoy opened this issue Sep 9, 2022 · 2 comments

Comments

@caseyjoy
Copy link
Contributor

caseyjoy commented Sep 9, 2022

Godot version

v4.0.alpha16.official [86dd3f3]

System information

Ubuntu 22.04.1 LTS

Issue description

When you have a GraphNode that contains a single node, moving the child node out of the GraphNode or deleting it will cause the editor to crash, and will also cause a running project to crash if you remove it via code.

Adding an additional node will cause it not to happen until you remove all but one node again, all but the last child node can be safely removed.

This also happened in v4.0.alpha15.official [432b25d] (but not in v3.5.stable.official [991bb6a] or v3.5.1.rc1.official [293c384])

ERROR: Index p_index = 0 is out of bounds (data.children.size() = 0).
   at: get_child (scene/main/node.cpp:1245)

================================================================
handle_crash: Program crashed with signal 11
Engine version: Godot Engine v4.0.alpha16.official (86dd3f312c4ff8ef8be04b9a210415d21f2ca269)
Dumping the backtrace. Please include this when reporting the bug to the project developer.
[1] /lib/x86_64-linux-gnu/libc.so.6(+0x42520) [0x7f36ce6ff520] (??:0)
[2] /home/c/Programs/Godot_v4.0-alpha16_linux.x86_64() [0x2a711b0] (??:0)
[3] /home/c/Programs/Godot_v4.0-alpha16_linux.x86_64() [0x2b12535] (??:0)
[4] /home/c/Programs/Godot_v4.0-alpha16_linux.x86_64() [0x426c444] (??:0)
[5] /home/c/Programs/Godot_v4.0-alpha16_linux.x86_64() [0x28cdfa4] (??:0)
[6] /home/c/Programs/Godot_v4.0-alpha16_linux.x86_64() [0x4897125] (??:0)
[7] /home/c/Programs/Godot_v4.0-alpha16_linux.x86_64() [0x42cdc07] (??:0)
[8] /home/c/Programs/Godot_v4.0-alpha16_linux.x86_64() [0x29929fc] (??:0)
[9] /home/c/Programs/Godot_v4.0-alpha16_linux.x86_64() [0xe32627] (??:0)
[10] /home/c/Programs/Godot_v4.0-alpha16_linux.x86_64() [0xdc6f59] (??:0)
[11] /lib/x86_64-linux-gnu/libc.so.6(+0x29d90) [0x7f36ce6e6d90] (??:0)
[12] /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0x80) [0x7f36ce6e6e40] (??:0)
[13] /home/c/Programs/Godot_v4.0-alpha16_linux.x86_64() [0xde2c9e] (??:0)
-- END OF BACKTRACE --
================================================================

Steps to reproduce

Minimal reproduction project steps:

  • Drag the TextEdit node out of the GraphNode, and into the Control node
    or
  • Run the project to crash it by removing the child node with queue_free()

In the editor:

  • Make a new project
  • Add a new User Interface scene (the type doesn't seem to make a difference, 2D Scene worked as well)
  • Add a GraphNode to the root Control node
  • Add another node as a child to the GraphNode (the type doesn't seem to make a difference, TextEdit, GraphNode,
  • Drag the child node out of the GraphNode (or delete it)
  • Editor will crash

While running:

  • Follow the In editor steps, but stop before removing the child node
  • Add a script to the child node of the GraphNode
  • Add queue_free() to func _ready():
  • Run the project
  • Running project will crash

Minimal reproduction project

test project 4 alpha 16.zip

@gotnospirit
Copy link
Contributor

The backtrace on Windows is a bit more explicit

ERROR: Index p_index = 0 is out of bounds (data.children.size() = 0).
   at: Node::get_child (scene\main\node.cpp:1230)

================================================================
CrashHandlerException: Program crashed
Engine version: Godot Engine v4.0.alpha.custom_build (27e132347324318567419ac5039d51338d7d4f0e)
Dumping the backtrace. Please include this when reporting the bug to the project developer.
[0] Control::get_size (C:\godot\scene\gui\control.cpp:1400)
[1] Control::get_rect (C:\godot\scene\gui\control.cpp:1419)
[2] GraphNode::_notification (C:\godot\scene\gui\graph_node.cpp:398)
[3] GraphNode::_notificationv (C:\godot\scene\gui\graph_node.h:38)
[4] Object::notification (C:\godot\core\object\object.cpp:792)
[5] CanvasItem::_redraw_callback (C:\godot\scene\main\canvas_item.cpp:136)
[6] call_with_variant_args_helper<CanvasItem> (C:\godot\core\variant\binder_common.h:267)
[7] call_with_variant_args<CanvasItem> (C:\godot\core\variant\binder_common.h:377)
[8] CallableCustomMethodPointer<CanvasItem>::call (C:\godot\core\object\callable_method_pointer.h:105)
[9] Callable::callp (C:\godot\core\variant\callable.cpp:51)
[10] MessageQueue::_call_function (C:\godot\core\object\message_queue.cpp:230)
[11] MessageQueue::flush (C:\godot\core\object\message_queue.cpp:277)
[12] SceneTree::physics_process (C:\godot\scene\main\scene_tree.cpp:431)
[13] Main::iteration (C:\godot\main\main.cpp:2975)
[14] OS_Windows::run (C:\godot\platform\windows\os_windows.cpp:907)
[15] widechar_main (C:\godot\platform\windows\godot_windows.cpp:179)
[16] _main (C:\godot\platform\windows\godot_windows.cpp:201)
[17] main (C:\godot\platform\windows\godot_windows.cpp:215)
[18] WinMain (C:\godot\platform\windows\godot_windows.cpp:229)
[19] __scrt_common_main_seh (D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:288)
[20] BaseThreadInitThunk
-- END OF BACKTRACE --
================================================================

Adding a print before the loop on slot_info reveals that slots and children are not sync after a delete

nb slots: 1, nb childs: 0

but we try to access a child using slot key without checking if it exists

if (s.draw_stylebox) {
Control *c = Object::cast_to<Control>(get_child(E.key));
Rect2 c_rect = c->get_rect();

I don't know what is slot_info exactly, so I can't tell if it should be in-sync with children count,
but as a quick fix, we can either put lines 397-400 in a if (c) condition, or add && get_child_count() > 0 in if (s.draw_stylebox at line 395.
The later option will also prevent this error ERROR: Index p_index = 0

@YuriSizov
Copy link
Contributor

This was a duplicate of #69082 (or rather the other way around 🙃) and it was fixed by #69284.

@github-project-automation github-project-automation bot moved this from In Progress to Done in 4.x Priority Issues Jan 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

4 participants