libsdl-org / SDL

Simple Directmedia Layer
https://libsdl.org
zlib License
10.14k stars 1.85k forks source link

[SDL3] Fullscreen window has `PENDING_OPERATION_LEAVE_FULLSCREEN` flag stuck after being restored from minimised #11507

Closed frenzibyte closed 1 day ago

frenzibyte commented 2 days ago

This flag causes any SDL operation that waits for window to be synced such as SDL_SetWindowSize/SDL_SetWindowPosition/SDL_RestoreWindow to get always stuck for a few seconds after the window has been restored from a minimised state at least once.

The flag seems to be added by this path specifically: https://github.com/libsdl-org/SDL/blob/18b7a2315c389107a433153f0a24d19d734996e8/src/video/cocoa/SDL_cocoawindow.m#L2623-L2625

And by debugging, that flag is never removed from the window, thus making every SDL operation that syncs the window get stuck until timeout.

It's slightly weird why window->flags & FULLSCREEN is included in the check when such flag is only added and cleared in the case where the window is in "fullscreen space" mode, judging by the existing NSWindow notifications that seem to be responsible for the state of such flag.

This can be tested on testwm or otherwise by including this diff and then minimising the window while it is in fullscreen at least once:

diff --git a/src/test/SDL_test_common.c b/src/test/SDL_test_common.c
index b434be494..d50aaa1ed 100644
--- a/src/test/SDL_test_common.c
+++ b/src/test/SDL_test_common.c
@@ -2517,6 +2517,7 @@ SDL_AppResult SDLTest_CommonEventMainCallbacks(SDLTest_CommonState *state, const
                         SDL_SetWindowFullscreen(window, true);
                     } else {
                         SDL_SetWindowFullscreen(window, false);
+                        SDL_SetWindowSize(window, 1024, 1024);
                     }
                 }
             } else if (withAlt) {

Result:

https://github.com/user-attachments/assets/2a96c8d6-db0e-4213-bdb3-39cf04e35258