summaryrefslogtreecommitdiff
path: root/platform
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <remi@verschelde.fr>2022-09-25 08:38:10 +0200
committerGitHub <noreply@github.com>2022-09-25 08:38:10 +0200
commit67f700d72686086820721f5f60418705def3b166 (patch)
tree190c5966a7a40c5f4b5def4bd7dedc4213517796 /platform
parent632dbab226356eb4395ee2c0aa202c5fcd912e7d (diff)
parentb66931946b0adb90e5539da8e54dfbeb02b33c4f (diff)
Merge pull request #66377 from bruvzg/macos_menu_cb_deferred
[macOS] Process menu callback after event processing step to avoid event queue corruption.
Diffstat (limited to 'platform')
-rw-r--r--platform/macos/display_server_macos.h6
-rw-r--r--platform/macos/display_server_macos.mm20
2 files changed, 21 insertions, 5 deletions
diff --git a/platform/macos/display_server_macos.h b/platform/macos/display_server_macos.h
index a27e0d5efa..e72273a681 100644
--- a/platform/macos/display_server_macos.h
+++ b/platform/macos/display_server_macos.h
@@ -179,6 +179,12 @@ private:
IOPMAssertionID screen_keep_on_assertion = kIOPMNullAssertionID;
+ struct MenuCall {
+ Variant tag;
+ Callable callback;
+ };
+ Vector<MenuCall> deferred_menu_calls;
+
const NSMenu *_get_menu_root(const String &p_menu_root) const;
NSMenu *_get_menu_root(const String &p_menu_root);
diff --git a/platform/macos/display_server_macos.mm b/platform/macos/display_server_macos.mm
index 34723c7d4b..1914c5f35d 100644
--- a/platform/macos/display_server_macos.mm
+++ b/platform/macos/display_server_macos.mm
@@ -565,11 +565,11 @@ void DisplayServerMacOS::menu_callback(id p_sender) {
}
if (value->callback != Callable()) {
- Variant tag = value->meta;
- Variant *tagp = &tag;
- Variant ret;
- Callable::CallError ce;
- value->callback.callp((const Variant **)&tagp, 1, ret, ce);
+ MenuCall mc;
+ mc.tag = value->meta;
+ mc.callback = value->callback;
+ deferred_menu_calls.push_back(mc);
+ // Do not run callback from here! If it is opening a new window or calling process_events, it will corrupt OS event queue and crash.
}
}
}
@@ -3280,6 +3280,16 @@ void DisplayServerMacOS::process_events() {
[NSApp sendEvent:event];
}
+ // Process "menu_callback"s.
+ for (MenuCall &E : deferred_menu_calls) {
+ Variant tag = E.tag;
+ Variant *tagp = &tag;
+ Variant ret;
+ Callable::CallError ce;
+ E.callback.callp((const Variant **)&tagp, 1, ret, ce);
+ }
+ deferred_menu_calls.clear();
+
if (!drop_events) {
_process_key_events();
Input::get_singleton()->flush_buffered_events();