We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 5067

Summary: SDL_Quit does not call VideoQuit when video was auto-initialized via SDL_CreateWindow
Product: SDL Reporter: Jay Petacat <libsdl.org>
Component: videoAssignee: Ryan C. Gordon <icculus>
Status: RESOLVED FIXED QA Contact: Sam Lantinga <slouken>
Severity: normal    
Priority: P2 CC: icculus
Version: HG 2.0Keywords: target-2.0.14
Hardware: x86   
OS: Other   

Description Jay Petacat 2020-03-30 04:37:05 UTC
When exiting testspriteminimal, my driver's VideoQuit function is not executed, even if I call SDL_Quit in the test's quit function (is it intentionally absent?). As far as I can tell, it is because the video subsystem's reference count is zero and SDL_PrivateShouldQuitSubsystem(SDL_INIT_VIDEO) returns false.

My expectation is that SDL_Quit should know what to cleanup in this situation. If a maintainer affirms this, I will attempt to develop a patch.

Tangentially, if omitting SDL_Quit is a supported scenario, how shall I ensure my VideoQuit gets executed? atexit?
Comment 1 Ryan C. Gordon 2020-06-27 01:41:12 UTC
(In reply to Jay Petacat from comment #0)
> When exiting testspriteminimal, my driver's VideoQuit function is not
> executed, even if I call SDL_Quit in the test's quit function (is it
> intentionally absent?).

It is not intentionally absent, and I have now fixed that in https://hg.libsdl.org/SDL/rev/84dc2aca3b52

> My expectation is that SDL_Quit should know what to cleanup in this
> situation. If a maintainer affirms this, I will attempt to develop a patch.

You are correct, I think this is an oversight because most things call SDL_Init() explicitly (the attempt to recover by calling SDL_VideoInit implicitly is a leftover from SDL 1.2, and we should probably remove this behavior for SDL 2.1).

> Tangentially, if omitting SDL_Quit is a supported scenario, how shall I
> ensure my VideoQuit gets executed? atexit?

It's not a supported scenario, it was just a mistake in testspriteminimal, I assume it was deleted when cutting down testsprite2.c to not use the test framework.

Your diagnosis was correct, and I've now corrected the init call in https://hg.libsdl.org/SDL/rev/22ef6c87d061

Thanks!

--ryan.