Leaving BaseButton.shortcut_feedback
enabled raises errors when a button is removed from the scene tree #83867
Description
Godot version
v4.2.beta2.official [f8818f8]
System information
Godot v4.2.beta2 - KDE neon 5.27 22.04 - X11 - Vulkan (Forward+) - integrated AMD Radeon Vega 11 Graphics (RADV RAVEN) () - AMD Ryzen 5 3400G with Radeon Vega Graphics (8 Threads)
Issue description
Using a button with a shortcut resource and shortcut_feedback
set to true
raises errors in the debug console if the node is being removed from the scene tree.
I'm attaching a project reproducing the error that uses SceneTree.change_scene_to_file()
to trigger the issue.
The following line shows up in the debugger when you hit Enter:
E 0:00:01:0012 start: Timer was not added to the SceneTree. Either add it or set autostart to true.
<C++ Error> Condition "!is_inside_tree()" is true.
<C++ Source> scene/main/timer.cpp:109 @ start()
Looking through Godot's source code, BaseButton::shortcut_input
instantiates a Timer node that is started, but the condition to determine if the button node is leaving the tree is not checked:
// void BaseButton::shortcut_input(const Ref<InputEvent> &p_event) {
if (shortcut_feedback) {
if (shortcut_feedback_timer == nullptr) {
shortcut_feedback_timer = memnew(Timer);
shortcut_feedback_timer->set_one_shot(true);
add_child(shortcut_feedback_timer);
shortcut_feedback_timer->set_wait_time(GLOBAL_GET("gui/timers/button_shortcut_feedback_highlight_time"));
shortcut_feedback_timer->connect("timeout", callable_mp(this, &BaseButton::_shortcut_feedback_timeout));
}
in_shortcut_feedback = true;
shortcut_feedback_timer->start();
}
Leaving shortcut_feedback
unchecked solves the issue.
Testing the project under Godot 4.0 and 4.1 raises no errors.
Steps to reproduce
- Add a button node to a scene
- Add a shortcut resource to it (be sure
shortcut_feedback
is enabled) - Have the user interact with the button by its shortcut
- Use
remove_child
to remove the button node after button is pressed
Activity