Skip to content

Commit dcdb763

Browse files
committed
cocoa: Make sure GL context destruction happens on the main thread.
Fixes #10900. (cherry picked from commit 5cb87ff)
1 parent 5c9f370 commit dcdb763

File tree

1 file changed

+25
-5
lines changed

1 file changed

+25
-5
lines changed

src/video/cocoa/SDL_cocoaopengl.m

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -507,13 +507,33 @@ int Cocoa_GL_SwapWindow(_THIS, SDL_Window * window)
507507
return 0;
508508
}}
509509

510+
static void DispatchedDeleteContext(SDL_GLContext context)
511+
{
512+
@autoreleasepool {
513+
SDLOpenGLContext *nscontext = (__bridge SDLOpenGLContext *)context;
514+
[nscontext cleanup];
515+
CFRelease(context);
516+
}
517+
}
518+
510519
void Cocoa_GL_DeleteContext(_THIS, SDL_GLContext context)
511-
{ @autoreleasepool
512520
{
513-
SDLOpenGLContext *nscontext = (__bridge SDLOpenGLContext *)context;
514-
[nscontext cleanup];
515-
CFRelease(context);
516-
}}
521+
if ([NSThread isMainThread]) {
522+
DispatchedDeleteContext(context);
523+
} else {
524+
if (SDL_opengl_async_dispatch) {
525+
dispatch_async(dispatch_get_main_queue(), ^{
526+
DispatchedDeleteContext(context);
527+
});
528+
} else {
529+
dispatch_sync(dispatch_get_main_queue(), ^{
530+
DispatchedDeleteContext(context);
531+
});
532+
}
533+
}
534+
535+
return true;
536+
}
517537

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

0 commit comments

Comments
 (0)