Skip to content

Fix SDL2 incomplete closedown causing crash on quit for AmigaOS 4#755

Draft
Copilot wants to merge 2 commits intomasterfrom
copilot/fix-569d43a8-85d3-4e51-a3eb-14c9824a8795
Draft

Fix SDL2 incomplete closedown causing crash on quit for AmigaOS 4#755
Copilot wants to merge 2 commits intomasterfrom
copilot/fix-569d43a8-85d3-4e51-a3eb-14c9824a8795

Conversation

Copy link
Copy Markdown

Copilot AI commented Sep 11, 2025

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:


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

@timfel
Copy link
Copy Markdown
Member

timfel commented Sep 11, 2025

@Jarod42 I hope you don't mind, I got curious and wanted to try this github thingy ;-)

Co-authored-by: timfel <46235+timfel@users.noreply.github.com>
Copilot AI changed the title [WIP] Please work on @Wargus/stratagus/issues/744 Fix SDL2 incomplete closedown causing crash on quit for AmigaOS 4 Sep 11, 2025
Copilot AI requested a review from timfel September 11, 2025 13:09
@timfel timfel requested a review from Jarod42 September 11, 2025 13:13
@Jarod42
Copy link
Copy Markdown
Member

Jarod42 commented Sep 11, 2025

No issues to test it (and even merge it if appropriate).

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