sdl2-compat: Check and initialize the video subsystem from within sdl2-compat when creating a window

From 76eb981a4c376bcaf615c0af37d46512ba45cfb8 Mon Sep 17 00:00:00 2001
From: Frank Praznik <[EMAIL REDACTED]>
Date: Tue, 17 Jun 2025 11:45:25 -0400
Subject: [PATCH] Check and initialize the video subsystem from within
 sdl2-compat when creating a window

SDL3 will implicitly initialize the video and event systems when creating a window, but that leaves the sdl2-compat globals uninitialized. Check and initialize the video subsystem from within sdl2-compat, if necessary, so that the sdl2-compat globals and hints are initialized along with the video system.
---
 src/sdl2_compat.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/src/sdl2_compat.c b/src/sdl2_compat.c
index 74119ae..39aa9a1 100644
--- a/src/sdl2_compat.c
+++ b/src/sdl2_compat.c
@@ -8993,6 +8993,13 @@ SDL_CreateWindow(const char *title, int x, int y, int w, int h, Uint32 flags)
     bool exclusive_fullscreen = false;
     bool manually_show = false;
 
+    /* This needs to be called from within sdl2-compat to initialize the hints and globals. */
+    if (!SDL_WasInit(SDL_INIT_VIDEO)) {
+        if (SDL_Init(SDL_INIT_VIDEO)) {
+            return NULL;
+        }
+    }
+
     CheckEventFilter();
 
     if ((flags & SDL2_WINDOW_FULLSCREEN_DESKTOP) == SDL2_WINDOW_FULLSCREEN_DESKTOP) {