godotengine / godot

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

Crash in Tabs without tabs #53915

Closed kalysti closed 2 years ago

kalysti commented 2 years ago

Godot version

4.0

System information

Windows 11

Issue description

Broken tabs.

CrashHandlerException: Program crashed
Engine version: Godot Engine v4.0.dev.mono.custom_build (c2a616f3ecc5fa0ee7d85507b971e7578000a562)
Dumping the backtrace. Please include this when reporting the bug on https://github.com/godotengine/godot/issues
[0] Tabs::gui_input (C:\godot4\godot\scene\gui\tabs.cpp:227)
[1] Control::_call_gui_input (C:\godot4\godot\scene\gui\control.cpp:817)
[2] Viewport::_gui_call_input (C:\godot4\godot\scene\main\viewport.cpp:1266)
[3] Viewport::_gui_input_event (C:\godot4\godot\scene\main\viewport.cpp:1498)
[4] Viewport::push_input (C:\godot4\godot\scene\main\viewport.cpp:2678)
[5] SubViewportContainer::input (C:\godot4\godot\scene\gui\subviewport_container.cpp:159)
[6] Node::_call_input (C:\godot4\godot\scene\main\node.cpp:2622)
[7] SceneTree::_call_input_pause (C:\godot4\godot\scene\main\scene_tree.cpp:886)
[8] Viewport::push_input (C:\godot4\godot\scene\main\viewport.cpp:2674)
[9] Window::_window_input (C:\godot4\godot\scene\main\window.cpp:920)
[10] call_with_variant_args<VisualScriptEditor,Ref<InputEvent> const &> (C:\godot4\godot\core\variant\binder_common.h:336)
[11] Callable::call (C:\godot4\godot\core\variant\callable.cpp:51)
[12] DisplayServerWindows::_dispatch_input_event (C:\godot4\godot\platform\windows\display_server_windows.cpp:1850)
[13] Input::_parse_input_event_impl (C:\godot4\godot\core\input\input.cpp:615)
[14] Input::parse_input_event (C:\godot4\godot\core\input\input.cpp:826)
[15] DisplayServerWindows::WndProc (C:\godot4\godot\platform\windows\display_server_windows.cpp:2577)
[16] WndProc (C:\godot4\godot\platform\windows\display_server_windows.cpp:2846)
-- END OF BACKTRACE --

Steps to reproduce

image

Minimal reproduction project

No response

kalysti commented 2 years ago

Working on a pr..

kalysti commented 2 years ago

Comes from this PR https://github.com/godotengine/godot/commit/3c5103ac1d9a97cfe94978896b50572c2138138f#diff-207bf4d86cb0c1e40300d31103077149117c0c1ba94a8db04c1793b57dc6eff4

YeldhamDev commented 2 years ago

Could you please provide a example project where the crash occurs?

kalysti commented 2 years ago

Okay, it's one of my mistakes. Childs of the Tabs Component are not automatically added to tabs. Why do I have to call the add_tab method for this? I mean they are childs, make no sense to add them manualy. Now I have also understood the stack trace.

So i blv the best solution is adding childs automatically to the Tabs component.

kalysti commented 2 years ago

Could you please provide a example project where the crash occurs?

Just create a Tabs Component, and add a TabContainer as Child -> Stack Trace. Its because gui input is not fowarded, because the Tabs Component are not adding childs automaticly.

YeldhamDev commented 2 years ago

Okay, it's one of my mistakes. Childs of the Tabs Component are not automatically added to tabs. Why do I have to call the add_tab method for this? I mean they are childs, make no sense to add them manualy. Now I have also understood the stack trace. So i blv the best solution is adding childs automatically to the Tabs component.

I will repeat the answer I gave you in that PR:

If you want a node that adds tabs automatically when children are added, use TabContainer. Tabs is a more fine grained node that gives you a lot of options, but you have to do stuff yourself.

kalysti commented 2 years ago

Never mind -> a stack trace is a stack trace. We need a solution for this.

kalysti commented 2 years ago

Childs needs to be add automaticly to the Tabs Component. Otherwise u cant solve the stack trace.

YuriSizov commented 2 years ago

You are not supposed to add any children to the Tabs control. Tabs control is just a tab bar. That's it. It can be used for any behavior you need from switching the tabs. TabContainer on the other hand is what you use to add child controls as tabs automatically. These two are not to be used together, and they are not a replacement for each other.

KoBeWi commented 2 years ago

Well the class description even tells you so

Simple tabs control, similar to TabContainer but is only in charge of drawing tabs, not interacting with children.

EDIT: As for the crash, it happens if the Tabs don't have any tab. Children don't affect anything.

It happens on this line: https://github.com/godotengine/godot/blob/468b987aa38b21b55c1cd8a8d4c03b8e1b2a1373/scene/gui/tabs.cpp#L227

gui_input() should probably check whether tabs are empty and just return if yes. Or if input in empty Tabs makes sense, it should check before accessing tabs.

kalysti commented 2 years ago

Well the class description even tells you so

Simple tabs control, similar to TabContainer but is only in charge of drawing tabs, not interacting with children.

EDIT: As for the crash, it happens if the Tabs don't have any tab. Children don't affect anything.

It happens on this line:

https://github.com/godotengine/godot/blob/468b987aa38b21b55c1cd8a8d4c03b8e1b2a1373/scene/gui/tabs.cpp#L227

gui_input() should probably check whether tabs are empty and just return if yes. Or if input in empty Tabs makes sense, it should check before accessing tabs.

Thanks for it, and also for renaming Tabs to TabBar, i blv now everybody will understand it directly 👍

zedutch commented 2 years ago

So has this been fixed now? Is anyone still working on this?

KoBeWi commented 2 years ago

It still needs a fix and there isn't any PR open right now.