@@ -124,31 +124,30 @@ static BOOL UIKit_ShowMessageBoxAlertController(const SDL_MessageBoxData *messag
124
124
return YES ;
125
125
}
126
126
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)
128
135
{
129
136
@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 );
135
139
}
136
140
}
137
141
138
142
bool UIKit_ShowMessageBox (const SDL_MessageBoxData *messageboxdata, int *buttonID)
139
143
{
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." );
151
149
}
150
+ return true ;
152
151
}
153
152
154
153
#endif // SDL_VIDEO_DRIVER_UIKIT
0 commit comments