Errors when opening dialog from manually sent close notification #100753
Description
Tested versions
Reproducible in (at least): 4.3, 4.4dev2, and 4.4dev7
I get the same behavior with both C# and GDscript
System information
Linux (Fedora 41 using Gnome)
Issue description
Motivation: When the user closes my application I would like to open a dialog prompting them to save if content was modified.
Issue:
When I listen for NOTIFICATION_WM_CLOSE_REQUEST
and show a dialog this works as expected. However, if I manually trigger the same notification from a button or menu (using get_tree().root.propagate_notification
) instead I get the following error:
E 0:00:01:0786 popup_repro.gd:11 @ _notification(): Parent node is busy setting up children, `add_child()` failed. Consider using `add_child.call_deferred(child)` instead.
<C++ Error> Condition "data.blocked > 0" is true.
<C++ Source> scene/main/node.cpp:1572 @ add_child()
<Stack Trace> popup_repro.gd:11 @ _notification()
popup_repro.gd:5 @ <anonymous lambda>()
This is similar to #34157 except I don't see the error when the close notification is sent from the window manager.
If I replace cd.popup_exclusive_centered(self)
with cd.popup_exclusive_centered.call_deferred(self)
this works as expected, but it's not clear why this should be necessary.
Steps to reproduce
- Open repro project
- Click the button
- Observe error
Minimal reproduction project (MRP)
Attached is a tiny repro project, the only code of which is repeated here:
extends Control
func _ready() -> void:
get_tree().set_auto_accept_quit(false)
$Button.pressed.connect(func(): get_tree().root.propagate_notification(NOTIFICATION_WM_CLOSE_REQUEST))
func _notification(what: int) -> void:
if (what == NOTIFICATION_WM_CLOSE_REQUEST):
var cd = ConfirmationDialog.new()
cd.get_ok_button().pressed.connect(func(): get_tree().quit())
cd.popup_exclusive_centered(self)
Activity