From 42607909a0b19b36c26be804c75b6050dba97af3 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Sat, 20 Feb 2021 22:51:57 -0800
Subject: [PATCH] Remove devices from the list after they've been disconnected
due to read errors.
This fixes problems with controllers not being re-detected when a computer goes to sleep and a controller is removed and plugged back in while it's asleep.
---
src/joystick/hidapi/SDL_hidapijoystick.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/src/joystick/hidapi/SDL_hidapijoystick.c b/src/joystick/hidapi/SDL_hidapijoystick.c
index 8c02cc415..d73ba4078 100644
--- a/src/joystick/hidapi/SDL_hidapijoystick.c
+++ b/src/joystick/hidapi/SDL_hidapijoystick.c
@@ -898,12 +898,13 @@ HIDAPI_UpdateDeviceList(void)
}
}
- /* Remove any devices that weren't seen */
+ /* Remove any devices that weren't seen or have been disconnected due to read errors */
device = SDL_HIDAPI_devices;
while (device) {
SDL_HIDAPI_Device *next = device->next;
- if (!device->seen) {
+ if (!device->seen ||
+ (device->driver && device->num_joysticks == 0 && !device->dev)) {
HIDAPI_DelDevice(device);
}
device = next;