From f9f13bf0221ff1d15dc79baffb380e13d51e6d92 Mon Sep 17 00:00:00 2001 From: Vinyl Darkscratch Date: Wed, 3 Oct 2018 05:51:37 -0700 Subject: [PATCH] Dispatch popup dialogues to main thread --- src/oneshot.cpp | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/oneshot.cpp b/src/oneshot.cpp index 9824f06..102ff87 100644 --- a/src/oneshot.cpp +++ b/src/oneshot.cpp @@ -31,6 +31,7 @@ #ifdef __APPLE__ #define OS_OSX + #include #else #define OS_LINUX #include @@ -503,7 +504,7 @@ bool Oneshot::msgbox(int type, const char *body, const char *title) // Messagebox data SDL_MessageBoxData data; - data.window = NULL;//p->window; + data.window = NULL; //p->window; data.colorScheme = 0; data.title = title; data.message = body; @@ -556,9 +557,22 @@ bool Oneshot::msgbox(int type, const char *body, const char *title) #ifdef OS_W32 PlaySoundW((LPCWSTR)sound, NULL, SND_ALIAS_ID | SND_ASYNC); #endif - int button; - SDL_ShowMessageBox(&data, &button); - return button ? true : false; + int *button; + + #ifdef OS_OSX + // Message boxes and UI changes must be performed from the main thread on macOS Mojave and above. + // This block ensures the message box will show from the main thread. + dispatch_sync(dispatch_get_main_queue(), + ^{ SDL_ShowMessageBox(&data, button); } + ); + + // dispatch_block_wait(dispatch_get_main_queue(), DISPATCH_TIME_FOREVER); + *button = 1; // XXX Setting the button's value doesn't seem to work. + #else + SDL_ShowMessageBox(&data, button); + #endif + + return (*button) ? true : false; } std::string Oneshot::textinput(const char* prompt, int char_limit, const char* fontName) {