From 184da780f583b9b13bc4b061229b7eae63871f2c Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Mon, 18 Nov 2024 12:13:29 -0800
Subject: [PATCH] Fixed a crash when unplugging a Steam Controller dongle
---
src/joystick/hidapi/SDL_hidapi_steam.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/src/joystick/hidapi/SDL_hidapi_steam.c b/src/joystick/hidapi/SDL_hidapi_steam.c
index 55a1b344cfc21..8820787df7c00 100644
--- a/src/joystick/hidapi/SDL_hidapi_steam.c
+++ b/src/joystick/hidapi/SDL_hidapi_steam.c
@@ -1250,7 +1250,9 @@ static void ControllerDisconnected(SDL_HIDAPI_Device *device, SDL_Joystick **joy
{
SDL_DriverSteam_Context *ctx = (SDL_DriverSteam_Context *)device->context;
- HIDAPI_JoystickDisconnected(device, device->joysticks[0]);
+ if (device->joysticks) {
+ HIDAPI_JoystickDisconnected(device, device->joysticks[0]);
+ }
ctx->connected = false;
*joystick = NULL;
}