SDL: Make sure we're actually running on Windows before using D3D renderers (d3765)

From d3765b27c201ca7c49e374805780089ee13ef5c8 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Mon, 8 Jul 2024 11:28:29 -0700
Subject: [PATCH] Make sure we're actually running on Windows before using D3D
 renderers

(cherry picked from commit e22c89536a4cc834f0c45de5fcfd9e641b08a037)
---
 src/render/direct3d/SDL_render_d3d.c     | 6 +++++-
 src/render/direct3d11/SDL_render_d3d11.c | 7 ++++++-
 2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/src/render/direct3d/SDL_render_d3d.c b/src/render/direct3d/SDL_render_d3d.c
index f117bd664d137..06a584f6240e7 100644
--- a/src/render/direct3d/SDL_render_d3d.c
+++ b/src/render/direct3d/SDL_render_d3d.c
@@ -1610,7 +1610,11 @@ SDL_Renderer *D3D_CreateRenderer(SDL_Window *window, Uint32 flags)
     renderer->driverdata = data;
 
     SDL_VERSION(&windowinfo.version);
-    SDL_GetWindowWMInfo(window, &windowinfo);
+    if (!SDL_GetWindowWMInfo(window, &windowinfo) ||
+        windowinfo.subsystem != SDL_SYSWM_WINDOWS) {
+        SDL_free(data);
+        return SDL_SetError("Couldn't get window handle");
+    }
 
     window_flags = SDL_GetWindowFlags(window);
     SDL_GetWindowSizeInPixels(window, &w, &h);
diff --git a/src/render/direct3d11/SDL_render_d3d11.c b/src/render/direct3d11/SDL_render_d3d11.c
index 8249256faff8e..72b713d01bd5a 100644
--- a/src/render/direct3d11/SDL_render_d3d11.c
+++ b/src/render/direct3d11/SDL_render_d3d11.c
@@ -813,7 +813,12 @@ static HRESULT D3D11_CreateSwapChain(SDL_Renderer *renderer, int w, int h)
 #if defined(__WIN32__) || defined(__WINGDK__)
         SDL_SysWMinfo windowinfo;
         SDL_VERSION(&windowinfo.version);
-        SDL_GetWindowWMInfo(renderer->window, &windowinfo);
+        if (!SDL_GetWindowWMInfo(renderer->window, &windowinfo) ||
+            windowinfo.subsystem != SDL_SYSWM_WINDOWS) {
+            SDL_SetError("Couldn't get window handle");
+            result = E_FAIL;
+            goto done;
+        }
 
         result = IDXGIFactory2_CreateSwapChainForHwnd(data->dxgiFactory,
                                                       (IUnknown *)data->d3dDevice,