Skip to content

Commit

Permalink
cocoa: Make sure GL context destruction happens on the main thread.
Browse files Browse the repository at this point in the history
Fixes #10900.

(cherry picked from commit 344546b)
  • Loading branch information
icculus committed Oct 25, 2024
1 parent 00f15dd commit 5cb87ff
Showing 1 changed file with 25 additions and 5 deletions.
30 changes: 25 additions & 5 deletions src/video/cocoa/SDL_cocoaopengl.m
Original file line number Diff line number Diff line change
Expand Up @@ -507,13 +507,33 @@ int Cocoa_GL_SwapWindow(_THIS, SDL_Window * window)
return 0;
}}

static void DispatchedDeleteContext(SDL_GLContext context)
{
@autoreleasepool {
SDLOpenGLContext *nscontext = (__bridge SDLOpenGLContext *)context;
[nscontext cleanup];
CFRelease(context);
}
}

void Cocoa_GL_DeleteContext(_THIS, SDL_GLContext context)
{ @autoreleasepool
{
SDLOpenGLContext *nscontext = (__bridge SDLOpenGLContext *)context;
[nscontext cleanup];
CFRelease(context);
}}
if ([NSThread isMainThread]) {
DispatchedDeleteContext(context);
} else {
if (SDL_opengl_async_dispatch) {
dispatch_async(dispatch_get_main_queue(), ^{
DispatchedDeleteContext(context);
});
} else {
dispatch_sync(dispatch_get_main_queue(), ^{
DispatchedDeleteContext(context);
});
}
}

return true;
}

/* We still support OpenGL as long as Apple offers it, deprecated or not, so disable deprecation warnings about it. */
#ifdef __clang__
Expand Down

0 comments on commit 5cb87ff

Please sign in to comment.