uikit: Use SDL_RunOnMainThread instead of dispatch_sync for message boxes.

Reference Issue #12741.
This commit is contained in:
Ryan C. Gordon
2025-05-01 18:28:53 -04:00
parent 691cc5bb5e
commit 193b0c8963

View File

@@ -124,31 +124,30 @@ static BOOL UIKit_ShowMessageBoxAlertController(const SDL_MessageBoxData *messag
return YES; return YES;
} }
static void UIKit_ShowMessageBoxImpl(const SDL_MessageBoxData *messageboxdata, int *buttonID, int *result) typedef struct UIKit_ShowMessageBoxData
{
const SDL_MessageBoxData *messageboxdata;
int *buttonID;
bool result;
} UIKit_ShowMessageBoxData;
static void SDLCALL UIKit_ShowMessageBoxMainThreadCallback(void *userdata)
{ {
@autoreleasepool { @autoreleasepool {
if (UIKit_ShowMessageBoxAlertController(messageboxdata, buttonID)) { UIKit_ShowMessageBoxData *data = (UIKit_ShowMessageBoxData *) userdata;
*result = true; data->result = UIKit_ShowMessageBoxAlertController(data->messageboxdata, data->buttonID);
} else {
*result = SDL_SetError("Could not show message box.");
}
} }
} }
bool UIKit_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonID) bool UIKit_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonID)
{ {
@autoreleasepool { UIKit_ShowMessageBoxData data = { messageboxdata, buttonID, false };
__block int result = true; if (!SDL_RunOnMainThread(UIKit_ShowMessageBoxMainThreadCallback, &data, true)) {
return false;
if ([NSThread isMainThread]) { } else if (!data.result) {
UIKit_ShowMessageBoxImpl(messageboxdata, buttonID, &result); return SDL_SetError("Could not show message box.");
} else {
dispatch_sync(dispatch_get_main_queue(), ^{
UIKit_ShowMessageBoxImpl(messageboxdata, buttonID, &result);
});
}
return result;
} }
return true;
} }
#endif // SDL_VIDEO_DRIVER_UIKIT #endif // SDL_VIDEO_DRIVER_UIKIT