cocoa: Change the new sync_dispatch hint to async_dispatch. This is so the default is safer.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
diff --git a/include/SDL_hints.h b/include/SDL_hints.h
index f50b5e0..02d5fc5 100644
--- a/include/SDL_hints.h
+++ b/include/SDL_hints.h
@@ -981,13 +981,19 @@ extern "C" {
* \brief A variable controlling whether dispatching OpenGL context updates should block the dispatching thread until the main thread finishes processing
*
* This variable can be set to the following values:
- * "0" - Dispatching OpenGL context updates will allow the dispatching thread to continue execution.
- * "1" - Dispatching OpenGL context updates will block the dispatching thread until the main thread finishes processing.
+ * "0" - Dispatching OpenGL context updates will block the dispatching thread until the main thread finishes processing (default).
+ * "1" - Dispatching OpenGL context updates will allow the dispatching thread to continue execution.
*
- * This hint only applies to Mac OS X
+ * Generally you want the default, but if you have OpenGL code in a background thread on a Mac, and the main thread
+ * hangs because it's waiting for that background thread, but that background thread is also hanging because it's
+ * waiting for the main thread to do an update, this might fix your issue.
+ *
+ * This hint only applies to macOS.
+ *
+ * This hint is available since SDL 2.24.0.
*
*/
-#define SDL_HINT_MAC_OPENGL_SYNC_DISPATCH "SDL_MAC_OPENGL_SYNC_DISPATCH"
+#define SDL_HINT_MAC_OPENGL_ASYNC_DISPATCH "SDL_MAC_OPENGL_ASYNC_DISPATCH"
/**
* \brief A variable setting the double click radius, in pixels.
diff --git a/src/video/cocoa/SDL_cocoaopengl.m b/src/video/cocoa/SDL_cocoaopengl.m
index 31fe948..91319d5 100644
--- a/src/video/cocoa/SDL_cocoaopengl.m
+++ b/src/video/cocoa/SDL_cocoaopengl.m
@@ -44,12 +44,12 @@
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
#endif
-static SDL_bool SDL_opengl_sync_dispatch = SDL_FALSE;
+static SDL_bool SDL_opengl_async_dispatch = SDL_FALSE;
static void SDLCALL
-SDL_OpenGLSyncDispatchChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
+SDL_OpenGLAsyncDispatchChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
{
- SDL_opengl_sync_dispatch = SDL_GetStringBoolean(hint, SDL_FALSE);
+ SDL_opengl_async_dispatch = SDL_GetStringBoolean(hint, SDL_FALSE);
}
@implementation SDLOpenGLContext : NSOpenGLContext
@@ -63,7 +63,7 @@ SDL_OpenGLSyncDispatchChanged(void *userdata, const char *name, const char *oldV
self->window = NULL;
}
- SDL_AddHintCallback(SDL_HINT_MAC_OPENGL_SYNC_DISPATCH, SDL_OpenGLSyncDispatchChanged, NULL);
+ SDL_AddHintCallback(SDL_HINT_MAC_OPENGL_ASYNC_DISPATCH, SDL_OpenGLAsyncDispatchChanged, NULL);
return self;
}
@@ -147,17 +147,17 @@ SDL_OpenGLSyncDispatchChanged(void *userdata, const char *name, const char *oldV
if ([NSThread isMainThread]) {
[super update];
} else {
- if (SDL_opengl_sync_dispatch) {
- dispatch_sync(dispatch_get_main_queue(), ^{ [super update]; });
- } else {
+ if (SDL_opengl_async_dispatch) {
dispatch_async(dispatch_get_main_queue(), ^{ [super update]; });
+ } else {
+ dispatch_sync(dispatch_get_main_queue(), ^{ [super update]; });
}
}
}
- (void)dealloc
{
- SDL_DelHintCallback(SDL_HINT_MAC_OPENGL_SYNC_DISPATCH, SDL_OpenGLSyncDispatchChanged, NULL);
+ SDL_DelHintCallback(SDL_HINT_MAC_OPENGL_ASYNC_DISPATCH, SDL_OpenGLAsyncDispatchChanged, NULL);
}
@end