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
  • Loading branch information
icculus committed Oct 24, 2024
1 parent dcd4ddb commit 344546b
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/video/cocoa/SDL_cocoaopengl.m
Original file line number Diff line number Diff line change
Expand Up @@ -523,13 +523,31 @@ bool Cocoa_GL_SwapWindow(SDL_VideoDevice *_this, SDL_Window *window)
}
}

bool Cocoa_GL_DestroyContext(SDL_VideoDevice *_this, SDL_GLContext context)
static void DispatchedDestroyContext(SDL_GLContext context)
{
@autoreleasepool {
SDL3OpenGLContext *nscontext = (__bridge SDL3OpenGLContext *)context;
[nscontext cleanup];
CFRelease(context);
}
}

bool Cocoa_GL_DestroyContext(SDL_VideoDevice *_this, SDL_GLContext context)
{
if ([NSThread isMainThread]) {
DispatchedDestroyContext(context);
} else {
if (SDL_opengl_async_dispatch) {
dispatch_async(dispatch_get_main_queue(), ^{
DispatchedDestroyContext(context);
});
} else {
dispatch_sync(dispatch_get_main_queue(), ^{
DispatchedDestroyContext(context);
});
}
}

return true;
}

Expand Down

0 comments on commit 344546b

Please sign in to comment.