Simple Directmedia Layer

cocoa: Make sure GL context destruction happens on the main thread.

Fixes #10900.

+19 -1
+19 -1
src/video/cocoa/SDL_cocoaopengl.m
··· 523 523 } 524 524 } 525 525 526 - bool Cocoa_GL_DestroyContext(SDL_VideoDevice *_this, SDL_GLContext context) 526 + static void DispatchedDestroyContext(SDL_GLContext context) 527 527 { 528 528 @autoreleasepool { 529 529 SDL3OpenGLContext *nscontext = (__bridge SDL3OpenGLContext *)context; 530 530 [nscontext cleanup]; 531 531 CFRelease(context); 532 532 } 533 + } 534 + 535 + bool Cocoa_GL_DestroyContext(SDL_VideoDevice *_this, SDL_GLContext context) 536 + { 537 + if ([NSThread isMainThread]) { 538 + DispatchedDestroyContext(context); 539 + } else { 540 + if (SDL_opengl_async_dispatch) { 541 + dispatch_async(dispatch_get_main_queue(), ^{ 542 + DispatchedDestroyContext(context); 543 + }); 544 + } else { 545 + dispatch_sync(dispatch_get_main_queue(), ^{ 546 + DispatchedDestroyContext(context); 547 + }); 548 + } 549 + } 550 + 533 551 return true; 534 552 } 535 553