File tree Expand file tree Collapse file tree 3 files changed +20
-8
lines changed Expand file tree Collapse file tree 3 files changed +20
-8
lines changed Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change 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 }
Original file line number Diff line number Diff 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 ;
You can’t perform that action at this time.
0 commit comments