From d73bd0d2f68ab65b6e9f110720880b271fc3dbef Mon Sep 17 00:00:00 2001
From: Cameron Gutman <[EMAIL REDACTED]>
Date: Mon, 3 Jan 2022 21:39:30 -0600
Subject: [PATCH] dinput: Don't crash in SDL_DINPUT_JoystickPresent if DInput
init failed
The WGI driver will call this regardless of whether our init succeeded.
---
src/joystick/windows/SDL_dinputjoystick.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/src/joystick/windows/SDL_dinputjoystick.c b/src/joystick/windows/SDL_dinputjoystick.c
index 843e4c3e11a..c2f53a93fe6 100644
--- a/src/joystick/windows/SDL_dinputjoystick.c
+++ b/src/joystick/windows/SDL_dinputjoystick.c
@@ -585,6 +585,10 @@ SDL_DINPUT_JoystickPresent(Uint16 vendor_id, Uint16 product_id, Uint16 version_n
{
Joystick_PresentData data;
+ if (dinput == NULL) {
+ return SDL_FALSE;
+ }
+
data.vendor = vendor_id;
data.product = product_id;
data.present = SDL_FALSE;