Skip to content

Commit e91493f

Browse files
committed
Merge pull request #102993 from bruvzg/fix_cb_win_erase
Prevent pending input event callbacks from erasing the window in the middle of a loop.
2 parents 93b6a17 + f710781 commit e91493f

File tree

3 files changed

+20
-8
lines changed

3 files changed

+20
-8
lines changed

platform/linuxbsd/x11/display_server_x11.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4227,13 +4227,17 @@ void DisplayServerX11::_dispatch_input_event(const Ref<InputEvent> &p_event) {
42274227
}
42284228
}
42294229
} else {
4230-
// Send to all windows.
4230+
// Send to all windows. Copy all pending callbacks, since callback can erase window.
4231+
Vector<Callable> cbs;
42314232
for (KeyValue<WindowID, WindowData> &E : windows) {
42324233
Callable callable = E.value.input_event_callback;
42334234
if (callable.is_valid()) {
4234-
callable.call(p_event);
4235+
cbs.push_back(callable);
42354236
}
42364237
}
4238+
for (const Callable &cb : cbs) {
4239+
cb.call(p_event);
4240+
}
42374241
}
42384242
}
42394243

platform/macos/display_server_macos.mm

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -411,13 +411,17 @@
411411
}
412412
}
413413
} else {
414-
// Send to all windows.
414+
// Send to all windows. Copy all pending callbacks, since callback can erase window.
415+
Vector<Callable> cbs;
415416
for (KeyValue<WindowID, WindowData> &E : windows) {
416417
Callable callable = E.value.input_event_callback;
417418
if (callable.is_valid()) {
418-
callable.call(p_event);
419+
cbs.push_back(callable);
419420
}
420421
}
422+
for (const Callable &cb : cbs) {
423+
cb.call(p_event);
424+
}
421425
}
422426
in_dispatch_input_event = false;
423427
}

platform/windows/display_server_windows.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4253,13 +4253,17 @@ void DisplayServerWindows::_dispatch_input_event(const Ref<InputEvent> &p_event)
42534253
}
42544254
}
42554255
} else {
4256-
// Send to all windows.
4257-
for (const KeyValue<WindowID, WindowData> &E : windows) {
4258-
const Callable callable = E.value.input_event_callback;
4256+
// Send to all windows. Copy all pending callbacks, since callback can erase window.
4257+
Vector<Callable> cbs;
4258+
for (KeyValue<WindowID, WindowData> &E : windows) {
4259+
Callable callable = E.value.input_event_callback;
42594260
if (callable.is_valid()) {
4260-
callable.call(p_event);
4261+
cbs.push_back(callable);
42614262
}
42624263
}
4264+
for (const Callable &cb : cbs) {
4265+
cb.call(p_event);
4266+
}
42634267
}
42644268

42654269
in_dispatch_input_event = false;

0 commit comments

Comments
 (0)