From 418eab29eb7f2a48c0a0e6ff3b7c646604b5f7e2 Mon Sep 17 00:00:00 2001
From: "Ryan C. Gordon" <[EMAIL REDACTED]>
Date: Thu, 1 May 2025 18:28:53 -0400
Subject: [PATCH] uikit: Use SDL_RunOnMainThread instead of dispatch_sync for
message boxes.
Reference Issue #12741.
(cherry picked from commit 193b0c896343c42e5831836d6144353430556dcb)
---
src/video/uikit/SDL_uikitmessagebox.m | 33 +++++++++++++--------------
1 file changed, 16 insertions(+), 17 deletions(-)
diff --git a/src/video/uikit/SDL_uikitmessagebox.m b/src/video/uikit/SDL_uikitmessagebox.m
index a57b3f76cdcca..b96f5fde70256 100644
--- a/src/video/uikit/SDL_uikitmessagebox.m
+++ b/src/video/uikit/SDL_uikitmessagebox.m
@@ -124,31 +124,30 @@ static BOOL UIKit_ShowMessageBoxAlertController(const SDL_MessageBoxData *messag
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 {
- if (UIKit_ShowMessageBoxAlertController(messageboxdata, buttonID)) {
- *result = true;
- } else {
- *result = SDL_SetError("Could not show message box.");
- }
+ UIKit_ShowMessageBoxData *data = (UIKit_ShowMessageBoxData *) userdata;
+ data->result = UIKit_ShowMessageBoxAlertController(data->messageboxdata, data->buttonID);
}
}
bool UIKit_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonID)
{
- @autoreleasepool {
- __block int result = true;
-
- if ([NSThread isMainThread]) {
- UIKit_ShowMessageBoxImpl(messageboxdata, buttonID, &result);
- } else {
- dispatch_sync(dispatch_get_main_queue(), ^{
- UIKit_ShowMessageBoxImpl(messageboxdata, buttonID, &result);
- });
- }
- return result;
+ UIKit_ShowMessageBoxData data = { messageboxdata, buttonID, false };
+ if (!SDL_RunOnMainThread(UIKit_ShowMessageBoxMainThreadCallback, &data, true)) {
+ return false;
+ } else if (!data.result) {
+ return SDL_SetError("Could not show message box.");
}
+ return true;
}
#endif // SDL_VIDEO_DRIVER_UIKIT