SDL
SDL copied to clipboard
Mac OS window persists and hangs after destroy window and quit
On development SDL3 branch:
#include <unistd.h>
#include <SDL3/SDL.h>
int main() {
SDL_Init(SDL_INIT_VIDEO);
SDL_Window * window = SDL_CreateWindow("Test", 800, 600, 0);
SDL_ShowWindow(window);
SDL_Event ev;
while (1) {
if (SDL_PollEvent(&ev)) {
if (ev.type == SDL_EVENT_QUIT)
break;
}
}
SDL_DestroyWindow(window);
SDL_Quit();
sleep(10);
return 0;
}
Reproduce:
- Launch program
- Close window
Expected:
- Window closes immediately
Actual:
- Window freezes until the end of program
This is a problem for my project where windows need to be opened/closed repeatedly.
This also reproduces on Linux with testsprite --windows 2: pressing the close button does nothing.
macOS requires pumping the events after destroying a window for the OS to process the change and remove it from the desktop. This has been the case going back to SDL2.
This also reproduces on Linux with
testsprite --windows 2: pressing the close button does nothing.
This is due to the test framework and testsprite not handling SDL_EVENT_WINDOW_CLOSE_REQUESTED (it's printed when event logging is enabled, but doesn't actually do anything). It works with only one window since SDL will just send SDL_EVENT_QUIT in that case.
macOS requires pumping the events after destroying a window for the OS to process the change and remove it from the desktop. This has been the case going back to SDL2.
Do you mean the user needs to do that? Is there documentation on this behavior?
I added a note to the SDL_DestroyWindow docs; in practice most apps will either pump the event queue regularly in their main loop logic, use the main callbacks, or be about to shut down after destroying their windows, so I don't think this issue needs further attention.
Pumping the events after closing the window still does not work on Mac OS.
I tried running the same code and pumping the events:
#include <SDL3/SDL.h>
#include <unistd.h>
int main() {
SDL_Init(SDL_INIT_VIDEO);
SDL_Window *window = SDL_CreateWindow("Test", 800, 600, 0);
SDL_ShowWindow(window);
SDL_Event ev;
while (1) {
if (SDL_PollEvent(&ev)) {
if (ev.type == SDL_EVENT_QUIT)
break;
}
}
SDL_DestroyWindow(window);
SDL_PumpEvents();
SDL_Quit();
sleep(10);
return 0;
}
And the window still happens to be stuck. I am using SDL 3.2.16