Skip to content

Commit 193b0c8

Browse files
committed
uikit: Use SDL_RunOnMainThread instead of dispatch_sync for message boxes.
Reference Issue #12741.
1 parent 691cc5b commit 193b0c8

File tree

1 file changed

+16
-17
lines changed

1 file changed

+16
-17
lines changed

src/video/uikit/SDL_uikitmessagebox.m

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -124,31 +124,30 @@ static BOOL UIKit_ShowMessageBoxAlertController(const SDL_MessageBoxData *messag
124124
return YES;
125125
}
126126

127-
static void UIKit_ShowMessageBoxImpl(const SDL_MessageBoxData *messageboxdata, int *buttonID, int *result)
127+
typedef struct UIKit_ShowMessageBoxData
128+
{
129+
const SDL_MessageBoxData *messageboxdata;
130+
int *buttonID;
131+
bool result;
132+
} UIKit_ShowMessageBoxData;
133+
134+
static void SDLCALL UIKit_ShowMessageBoxMainThreadCallback(void *userdata)
128135
{
129136
@autoreleasepool {
130-
if (UIKit_ShowMessageBoxAlertController(messageboxdata, buttonID)) {
131-
*result = true;
132-
} else {
133-
*result = SDL_SetError("Could not show message box.");
134-
}
137+
UIKit_ShowMessageBoxData *data = (UIKit_ShowMessageBoxData *) userdata;
138+
data->result = UIKit_ShowMessageBoxAlertController(data->messageboxdata, data->buttonID);
135139
}
136140
}
137141

138142
bool UIKit_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonID)
139143
{
140-
@autoreleasepool {
141-
__block int result = true;
142-
143-
if ([NSThread isMainThread]) {
144-
UIKit_ShowMessageBoxImpl(messageboxdata, buttonID, &result);
145-
} else {
146-
dispatch_sync(dispatch_get_main_queue(), ^{
147-
UIKit_ShowMessageBoxImpl(messageboxdata, buttonID, &result);
148-
});
149-
}
150-
return result;
144+
UIKit_ShowMessageBoxData data = { messageboxdata, buttonID, false };
145+
if (!SDL_RunOnMainThread(UIKit_ShowMessageBoxMainThreadCallback, &data, true)) {
146+
return false;
147+
} else if (!data.result) {
148+
return SDL_SetError("Could not show message box.");
151149
}
150+
return true;
152151
}
153152

154153
#endif // SDL_VIDEO_DRIVER_UIKIT

0 commit comments

Comments
 (0)