sdl2-compat: quit: Ignore subsystem ref count in SDL_(Audio|Video)Quit

From 7e821899a0ba821cdedb4cd51b93f56646c4dc1c Mon Sep 17 00:00:00 2001
From: Cameron Gutman <[EMAIL REDACTED]>
Date: Thu, 27 Feb 2025 19:12:21 -0600
Subject: [PATCH] quit: Ignore subsystem ref count in SDL_(Audio|Video)Quit

Real SDL2 always uninitializes the subsystems here, regardless of remaining refcount.
---
 src/sdl2_compat.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/src/sdl2_compat.c b/src/sdl2_compat.c
index ddf369e..8ba2e9b 100644
--- a/src/sdl2_compat.c
+++ b/src/sdl2_compat.c
@@ -6193,7 +6193,10 @@ SDL_AudioInit(const char *driver_name)
 SDL_DECLSPEC void SDLCALL
 SDL_AudioQuit(void)
 {
-    SDL_QuitSubSystem(SDL_INIT_AUDIO);
+    /* SDL_AudioQuit() ignores subsystem refcounting */
+    while (SDL_WasInit(SDL_INIT_AUDIO)) {
+        SDL_QuitSubSystem(SDL_INIT_AUDIO);
+    }
 }
 
 SDL_DECLSPEC int SDLCALL
@@ -6401,7 +6404,10 @@ SDL_VideoInit(const char *driver_name)
 SDL_DECLSPEC void SDLCALL
 SDL_VideoQuit(void)
 {
-    SDL_QuitSubSystem(SDL_INIT_VIDEO);
+    /* SDL_VideoQuit() ignores subsystem refcounting */
+    while (SDL_WasInit(SDL_INIT_VIDEO)) {
+        SDL_QuitSubSystem(SDL_INIT_VIDEO);
+    }
 }
 
 SDL_DECLSPEC int SDLCALL