sdl2-compat: Add an early check for SDL 3 window creation error

From da86b665aeb8b2b468c6a56df7c92be175974ee1 Mon Sep 17 00:00:00 2001
From: Daniel Bomar <[EMAIL REDACTED]>
Date: Tue, 4 Nov 2025 14:24:26 -0600
Subject: [PATCH] Add an early check for SDL 3 window creation error

This makes sure to preserve error messages set by SDL 3
---
 src/sdl2_compat.c | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/src/sdl2_compat.c b/src/sdl2_compat.c
index d2f74cb..1575d99 100644
--- a/src/sdl2_compat.c
+++ b/src/sdl2_compat.c
@@ -9213,14 +9213,16 @@ SDL_CreateWindow(const char *title, int x, int y, int w, int h, Uint32 flags)
         }
     }
 
-    if (exclusive_fullscreen) {
-        ApplyFullscreenMode(window);
-        SDL3_SetWindowFullscreen(window, true);
-    }
-    if (manually_show) {
-        SDL3_ShowWindow(window);
+    if (window) {
+        if (exclusive_fullscreen) {
+            ApplyFullscreenMode(window);
+            SDL3_SetWindowFullscreen(window, true);
+        }
+        if (manually_show) {
+            SDL3_ShowWindow(window);
+        }
+        FinishWindowCreation(window);
     }
-    FinishWindowCreation(window);
 
     return window;
 }
@@ -9285,7 +9287,9 @@ SDL_CreateWindowFrom(const void *data)
     window = SDL3_CreateWindowWithProperties(props);
     SDL3_DestroyProperties(props);
 
-    FinishWindowCreation(window);
+    if (window) {
+        FinishWindowCreation(window);
+    }
 
     return window;
 }