Fix SDL2 incomplete closedown causing crash on quit for AmigaOS 4
Fixes issue #744 where calling just SDL_Quit() is insufficient for proper SDL cleanup on AmigaOS 4, leading to a recoverable alert about "not all resources freed" that hangs both the Stratagus application and the shell/Workbench task from which it was started.
Problem
The current SDL cleanup implementation only calls SDL_Quit() without properly destroying SDL objects first:
// Current problematic cleanup
atexit(SDL_Quit); // In normal exit
SDL_Quit(); // In debug signal handler
On AmigaOS 4, the OpenGL implementation requires all SDL resources to be explicitly freed before calling SDL_Quit(), otherwise it triggers a system alert that blocks the application.
Solution
Implemented a comprehensive CleanUpVideoSdl() function that properly destroys all SDL resources in the correct order before calling SDL_Quit():
static void CleanUpVideoSdl()
{
if (TheRenderer) {
SDL_DestroyRenderer(TheRenderer);
TheRenderer = nullptr;
}
if (TheWindow) {
SDL_DestroyWindow(TheWindow);
TheWindow = nullptr;
}
if (Video.blankCursor) {
Video.blankCursor.reset();
}
SDL_StopTextInput();
SDL_Quit();
}
The function is now used in both normal exit (atexit(CleanUpVideoSdl)) and debug signal handlers, ensuring complete resource cleanup in all scenarios.
Changes
-
Added:
CleanUpVideoSdl()static function with proper resource cleanup sequence -
Updated: Normal exit handler to use new cleanup function instead of raw
SDL_Quit() - Updated: Debug signal handler to use new cleanup function for consistent behavior
This implementation follows the exact solution suggested in the issue and should resolve the hanging problem on AmigaOS 4 while maintaining compatibility with all other platforms.
[!WARNING]
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
esm.ubuntu.com
- Triggering command:
/usr/lib/apt/methods/https(dns block)If you need me to access, download, or install something from one of these locations, you can either:
- Configure Actions setup steps to set up my environment, which run before the firewall is enabled
- Add the appropriate URLs or hosts to the custom allowlist in this repository's Copilot coding agent settings (admins only)
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.
@Jarod42 I hope you don't mind, I got curious and wanted to try this github thingy ;-)
No issues to test it (and even merge it if appropriate).