From 361218ce155e69704f41f8b6a0486dee1f0de459 Mon Sep 17 00:00:00 2001 From: Frank Praznik Date: Wed, 26 Mar 2025 18:01:42 -0400 Subject: [PATCH] cocoa: Re-add sync timeout This should never happen, but it's a failsafe against future bugs or odd configurations (cherry picked from commit 05d23cae736bb4d362ead87571c210451c7a3859) --- src/video/cocoa/SDL_cocoawindow.m | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/video/cocoa/SDL_cocoawindow.m b/src/video/cocoa/SDL_cocoawindow.m index 2a0527b744..c5dec56bdd 100644 --- a/src/video/cocoa/SDL_cocoawindow.m +++ b/src/video/cocoa/SDL_cocoawindow.m @@ -3264,14 +3264,23 @@ bool Cocoa_SetWindowOpacity(SDL_VideoDevice *_this, SDL_Window *window, float op bool Cocoa_SyncWindow(SDL_VideoDevice *_this, SDL_Window *window) { - bool result = true; + bool result = false; @autoreleasepool { + const Uint64 timeout = SDL_GetTicksNS() + SDL_MS_TO_NS(2500); SDL_CocoaWindowData *data = (__bridge SDL_CocoaWindowData *)window->internal; - do { + for (;;) { SDL_PumpEvents(); - } while ([data.listener hasPendingWindowOperation]); + + result = ![data.listener hasPendingWindowOperation]; + if (result || SDL_GetTicksNS() >= timeout) { + break; + } + + // Small delay before going again. + SDL_Delay(10); + } } return result;