SDL: Clear the subsystem ref count when shutting down subsystems in the main quit

From c33e4c998db4c1019417b4f99e79d4cba1db9326 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Wed, 20 Mar 2024 15:45:13 -0700
Subject: [PATCH] Clear the subsystem ref count when shutting down subsystems
 in the main quit

This prevents dependent subsystems from being deinitialized multiple times
---
 src/SDL.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/src/SDL.c b/src/SDL.c
index f010ad380ef92..99b2bf04304e1 100644
--- a/src/SDL.c
+++ b/src/SDL.c
@@ -131,7 +131,11 @@ static void SDL_DecrementSubsystemRefCount(Uint32 subsystem)
 {
     const int subsystem_index = SDL_MostSignificantBitIndex32(subsystem);
     if ((subsystem_index >= 0) && (SDL_SubsystemRefCount[subsystem_index] > 0)) {
-        --SDL_SubsystemRefCount[subsystem_index];
+        if (SDL_bInMainQuit) {
+            SDL_SubsystemRefCount[subsystem_index] = 0;
+        } else {
+            --SDL_SubsystemRefCount[subsystem_index];
+        }
     }
 }