[macOS] Process menu callback after event processing step to avoid event queue corruption.
This commit is contained in:
parent
f74491fdee
commit
b66931946b
|
@ -179,6 +179,12 @@ private:
|
||||||
|
|
||||||
IOPMAssertionID screen_keep_on_assertion = kIOPMNullAssertionID;
|
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;
|
const NSMenu *_get_menu_root(const String &p_menu_root) const;
|
||||||
NSMenu *_get_menu_root(const String &p_menu_root);
|
NSMenu *_get_menu_root(const String &p_menu_root);
|
||||||
|
|
||||||
|
|
|
@ -565,11 +565,11 @@ void DisplayServerMacOS::menu_callback(id p_sender) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (value->callback != Callable()) {
|
if (value->callback != Callable()) {
|
||||||
Variant tag = value->meta;
|
MenuCall mc;
|
||||||
Variant *tagp = &tag;
|
mc.tag = value->meta;
|
||||||
Variant ret;
|
mc.callback = value->callback;
|
||||||
Callable::CallError ce;
|
deferred_menu_calls.push_back(mc);
|
||||||
value->callback.callp((const Variant **)&tagp, 1, ret, ce);
|
// 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];
|
[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) {
|
if (!drop_events) {
|
||||||
_process_key_events();
|
_process_key_events();
|
||||||
Input::get_singleton()->flush_buffered_events();
|
Input::get_singleton()->flush_buffered_events();
|
||||||
|
|
Loading…
Reference in New Issue