SDL icon indicating copy to clipboard operation
SDL copied to clipboard

Mac OS window persists and hangs after destroy window and quit

Open rongcuid opened this issue 1 year ago • 3 comments

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.

rongcuid avatar Jun 21 '24 17:06 rongcuid

This also reproduces on Linux with testsprite --windows 2: pressing the close button does nothing.

madebr avatar Jun 21 '24 23:06 madebr

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.

Kontrabant avatar Jun 22 '24 14:06 Kontrabant

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?

rongcuid avatar Jun 22 '24 19:06 rongcuid

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.

icculus avatar Jan 04 '25 08:01 icculus

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

hmatheisen avatar Jun 17 '25 13:06 hmatheisen