1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-04 12:00:25 +00:00

Prevent pending input event callbacks from erasing the window in the middle of a loop.

This commit is contained in:
Pāvels Nadtočajevs
2025-02-18 15:16:51 +02:00
parent 93d2706930
commit f710781b16
3 changed files with 20 additions and 8 deletions

View File

@@ -4227,13 +4227,17 @@ void DisplayServerX11::_dispatch_input_event(const Ref<InputEvent> &p_event) {
}
}
} else {
// Send to all windows.
// Send to all windows. Copy all pending callbacks, since callback can erase window.
Vector<Callable> cbs;
for (KeyValue<WindowID, WindowData> &E : windows) {
Callable callable = E.value.input_event_callback;
if (callable.is_valid()) {
callable.call(p_event);
cbs.push_back(callable);
}
}
for (const Callable &cb : cbs) {
cb.call(p_event);
}
}
}

View File

@@ -411,13 +411,17 @@ void DisplayServerMacOS::_dispatch_input_event(const Ref<InputEvent> &p_event) {
}
}
} else {
// Send to all windows.
// Send to all windows. Copy all pending callbacks, since callback can erase window.
Vector<Callable> cbs;
for (KeyValue<WindowID, WindowData> &E : windows) {
Callable callable = E.value.input_event_callback;
if (callable.is_valid()) {
callable.call(p_event);
cbs.push_back(callable);
}
}
for (const Callable &cb : cbs) {
cb.call(p_event);
}
}
in_dispatch_input_event = false;
}

View File

@@ -4253,13 +4253,17 @@ void DisplayServerWindows::_dispatch_input_event(const Ref<InputEvent> &p_event)
}
}
} else {
// Send to all windows.
for (const KeyValue<WindowID, WindowData> &E : windows) {
const Callable callable = E.value.input_event_callback;
// Send to all windows. Copy all pending callbacks, since callback can erase window.
Vector<Callable> cbs;
for (KeyValue<WindowID, WindowData> &E : windows) {
Callable callable = E.value.input_event_callback;
if (callable.is_valid()) {
callable.call(p_event);
cbs.push_back(callable);
}
}
for (const Callable &cb : cbs) {
cb.call(p_event);
}
}
in_dispatch_input_event = false;