sdl12-compat: Fixed returning invalid information for non-X11 video drivers

From 7b67acc2be7dbd5802671c7e12d50204de874ba8 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Thu, 8 Sep 2022 16:16:02 -0700
Subject: [PATCH] Fixed returning invalid information for non-X11 video drivers

---
 src/SDL12_compat.c | 44 ++++++++++++++++++++++++++------------------
 1 file changed, 26 insertions(+), 18 deletions(-)

diff --git a/src/SDL12_compat.c b/src/SDL12_compat.c
index 4710ad97..3bb9445e 100644
--- a/src/SDL12_compat.c
+++ b/src/SDL12_compat.c
@@ -7020,26 +7020,34 @@ SDL_GetWMInfo(SDL12_SysWMinfo *info12)
         return 0;  /* some programs only test against 0, not -1 */
     }
 
-#if defined(SDL_VIDEO_DRIVER_WINDOWS)
-    SDL_assert(info20.subsystem == SDL_SYSWM_WINDOWS);
-    info12->window = temp_window ? 0 : info20.info.win.window;
-    if (SDL_VERSIONNUM(info12->version.major, info12->version.minor, info12->version.patch) >= SDL_VERSIONNUM(1, 2, 5)) {
-        info12->hglrc = (HGLRC) VideoGLContext20;
+#if defined(_WIN32)
+    if (info20.subsystem == SDL_SYSWM_WINDOWS) {
+        info12->window = temp_window ? 0 : info20.info.win.window;
+        if (SDL_VERSIONNUM(info12->version.major, info12->version.minor, info12->version.patch) >= SDL_VERSIONNUM(1, 2, 5)) {
+            info12->hglrc = (HGLRC) VideoGLContext20;
+        }
+    } else {
+        SDL20_SetError("No SysWM information available");
+        return 0;  /* some programs only test against 0, not -1 */
     }
 #elif defined(SDL_VIDEO_DRIVER_X11)
-    SDL_assert(info20.subsystem == SDL_SYSWM_X11);
-    info12->subsystem = SDL12_SYSWM_X11;
-    info12->info.x11.display = info20.info.x11.display;
-    info12->info.x11.window = temp_window ? 0 : info20.info.x11.window;
-    if (SDL_VERSIONNUM(info12->version.major, info12->version.minor, info12->version.patch) >= SDL_VERSIONNUM(1, 0, 2)) {
-        info12->info.x11.fswindow = 0;  /* these don't exist in SDL2. */
-        info12->info.x11.wmwindow = 0;
-    }
-    if (SDL_VERSIONNUM(info12->version.major, info12->version.minor, info12->version.patch) >= SDL_VERSIONNUM(1, 2, 12)) {
-        info12->info.x11.gfxdisplay = info20.info.x11.display;  /* shrug */
-    }
-    info12->info.x11.lock_func = x11_lock_display;  /* just no-ops for now */
-    info12->info.x11.unlock_func = x11_unlock_display;
+    if (info20.subsystem == SDL_SYSWM_X11) {
+        info12->subsystem = SDL12_SYSWM_X11;
+        info12->info.x11.display = info20.info.x11.display;
+        info12->info.x11.window = temp_window ? 0 : info20.info.x11.window;
+        if (SDL_VERSIONNUM(info12->version.major, info12->version.minor, info12->version.patch) >= SDL_VERSIONNUM(1, 0, 2)) {
+            info12->info.x11.fswindow = 0;  /* these don't exist in SDL2. */
+            info12->info.x11.wmwindow = 0;
+        }
+        if (SDL_VERSIONNUM(info12->version.major, info12->version.minor, info12->version.patch) >= SDL_VERSIONNUM(1, 2, 12)) {
+            info12->info.x11.gfxdisplay = info20.info.x11.display;  /* shrug */
+        }
+        info12->info.x11.lock_func = x11_lock_display;  /* just no-ops for now */
+        info12->info.x11.unlock_func = x11_unlock_display;
+    } else {
+        SDL20_SetError("No SysWM information available");
+        return 0;  /* some programs only test against 0, not -1 */
+    }
 #else
     info12->data = 0;  /* shrug */
 #endif