SDL: video: Unload GL/Vulkan when shutting down the video subsystem (12d85)

From 12d85408001d62d0eeb83d3e3c836b3de8a7d539 Mon Sep 17 00:00:00 2001
From: Frank Praznik <[EMAIL REDACTED]>
Date: Sun, 21 Dec 2025 11:11:44 -0500
Subject: [PATCH] video: Unload GL/Vulkan when shutting down the video
 subsystem

If GL/Vulkan was loaded manually via a SDL_X_LoadLibrary() call instead of via window flags or through the GPU or renderer system, and there is no matching SDL_X_UnloadLibrary() call, the library instance won't be automatically unloaded while shutting down the video system, as the refcount won't go to zero, which can cause problems with some backends, and leaves a leaked DLL/SO handle when the global video object is destroyed.

Ensure that the libraries are unloaded after destroying the windows, but before shutting down the video backend, to prevent a leak and possible driver errors when shutting down the video backend.

(cherry picked from commit 37fca1fdcf75dd62b60b364ab747b17e661d85fc)
---
 src/video/SDL_video.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/src/video/SDL_video.c b/src/video/SDL_video.c
index fdb40352ce8ea..51ab382354aa9 100644
--- a/src/video/SDL_video.c
+++ b/src/video/SDL_video.c
@@ -4443,6 +4443,16 @@ void SDL_VideoQuit(void)
     while (_this->windows) {
         SDL_DestroyWindow(_this->windows);
     }
+
+    if (_this->gl_config.driver_loaded && _this->GL_UnloadLibrary) {
+        _this->GL_UnloadLibrary(_this);
+        _this->gl_config.driver_loaded = 0;
+    }
+    if (_this->vulkan_config.loader_loaded && _this->Vulkan_UnloadLibrary) {
+        _this->Vulkan_UnloadLibrary(_this);
+        _this->vulkan_config.loader_loaded = 0;
+    }
+
     _this->VideoQuit(_this);
 
     for (i = _this->num_displays; i--; ) {