Skip to content

fix: don't call SDL_Quit from the SDL2 video driver - #1997

Merged
Flow86 merged 1 commit into
Return-To-The-Roots:masterfrom
klaustopher:fix/sdl-quit-shutdown-crash
Oct 24, 2026
Merged

Flow86 merged 1 commit into
Return-To-The-Roots:masterfrom
klaustopher:fix/sdl-quit-shutdown-crash

Conversation

@klaustopher

Copy link
Copy Markdown
Contributor

Hi,

I was looking into ways to play Siedler 2 on my Mac and came across this project. Thanks for the effort, greatly appreciated! It builds natively on Apple Silicon and works nicely, but it crashed when I closed the window.

Short debug session: VideoSDL2::CleanUp calls SDL_Quit(), which shuts down all of SDL, including the audio subsystem the SDL audio driver still holds. That driver is only cleaned up later, during static destruction at exit, so AudioSDL::~AudioSDL calls Mix_CloseAudio/SDL_QuitSubSystem on an already terminated SDL. Classic SDL2 tolerated that, but sdl2-compat on SDL3 (what Homebrew ships as sdl2 now) crashes.

Removing the call fixes it. Each driver quits only the subsystem it initialized, and SDL shuts down with the last one.

Stack (macOS crash report)

libc++abi std::terminate()
libaudioSDL.dylib AudioSDL::~AudioSDL()
s25client AudioDriverWrapper::~AudioDriverWrapper()
s25client Singleton<AudioDriverWrapper, ...>::DestroySingleton()
libsystem_c exit

VideoSDL2::CleanUp shut down all of SDL, while the SDL audio driver
still had its subsystem initialized. The audio driver is only cleaned
up later during static destruction, so it called Mix_CloseAudio,
Mix_Quit and SDL_QuitSubSystem on an already terminated SDL.

Classic SDL2 tolerated this, but sdl2-compat on top of SDL3 (what
Homebrew ships as sdl2 now) crashes in AudioSDL::~AudioSDL on exit.

Each driver now only quits the subsystem it initialized. SDL
refcounts subsystems and shuts itself down with the last one.
@Flow86
Flow86 merged commit a3dd232 into Return-To-The-Roots:master Oct 24, 2026
17 of 18 checks passed
@klaustopher
klaustopher deleted the fix/sdl-quit-shutdown-crash branch October 24, 2026 07:49
@klaustopher

Copy link
Copy Markdown
Contributor Author

This is the fastest I have ever gotten a feedback on a PR 👍 Thanks

@Flamefire

Copy link
Copy Markdown
Member

Are we missing anything with this now? I.e. any (sub)system that won't be closed now?
Probably doesn't matter much as it's on shutdown anyway, but just to be sure

@Flow86

Flow86 commented Oct 24, 2026

Copy link
Copy Markdown
Member

SDL_quit is not essential, so it's fine

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants