macOS: Fix crash when triggering some global menu actions with the mouse

This commit is contained in:
Kovid Goyal 2018-06-06 22:53:07 +05:30
parent 2e8d19601b
commit ad44e1a515
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
3 changed files with 25 additions and 2 deletions

View File

@ -751,6 +751,18 @@ process_pending_closes(ChildMonitor *self) {
return has_open_windows; return has_open_windows;
} }
#ifdef __APPLE__
// If we create new OS windows during wait_events(), using global menu actions
// via the mouse causes a crash because of the way autorelease pools work in
// glfw/cocoa. So we use a flag instead.
static unsigned int cocoa_pending_actions = 0;
void
set_cocoa_pending_action(CocoaPendingAction action) {
cocoa_pending_actions |= action;
}
#endif
static PyObject* static PyObject*
main_loop(ChildMonitor *self, PyObject *a UNUSED) { main_loop(ChildMonitor *self, PyObject *a UNUSED) {
#define main_loop_doc "The main thread loop" #define main_loop_doc "The main thread loop"
@ -761,6 +773,13 @@ main_loop(ChildMonitor *self, PyObject *a UNUSED) {
if (global_state.has_pending_resizes) process_pending_resizes(now); if (global_state.has_pending_resizes) process_pending_resizes(now);
render(now); render(now);
wait_for_events(); wait_for_events();
#ifdef __APPLE__
if (cocoa_pending_actions) {
if (cocoa_pending_actions & PREFERENCES_WINDOW) { call_boss(edit_config_file, NULL); }
if (cocoa_pending_actions & NEW_OS_WINDOW) { call_boss(new_os_window, NULL); }
cocoa_pending_actions = 0;
}
#endif
parse_input(self); parse_input(self);
if (global_state.close_all_windows) close_all_windows(); if (global_state.close_all_windows) close_all_windows();
has_open_windows = process_pending_closes(self); has_open_windows = process_pending_closes(self);

View File

@ -65,12 +65,12 @@ find_app_name(void) {
- (void) show_preferences : (id)sender { - (void) show_preferences : (id)sender {
(void)sender; (void)sender;
call_boss(edit_config_file, NULL); set_cocoa_pending_action(PREFERENCES_WINDOW);
} }
- (void) new_os_window : (id)sender { - (void) new_os_window : (id)sender {
(void)sender; (void)sender;
call_boss(new_os_window, NULL); set_cocoa_pending_action(NEW_OS_WINDOW);
} }

View File

@ -190,4 +190,8 @@ FONTS_DATA_HANDLE load_fonts_data(double, double, double);
void send_prerendered_sprites_for_window(OSWindow *w); void send_prerendered_sprites_for_window(OSWindow *w);
#ifdef __APPLE__ #ifdef __APPLE__
void get_cocoa_key_equivalent(int, int, unsigned short*, int*); void get_cocoa_key_equivalent(int, int, unsigned short*, int*);
typedef enum {
PREFERENCES_WINDOW = 1, NEW_OS_WINDOW = 2
} CocoaPendingAction;
void set_cocoa_pending_action(CocoaPendingAction action);
#endif #endif