From c579033abfcf414e84eb0249ed1c60e30b3a9d61 Mon Sep 17 00:00:00 2001 From: Eric Warmenhoven Date: Sat, 10 Aug 2024 10:38:56 -0400 Subject: [PATCH] macos: fix hid driver crash on disconnecting controller second time (#16860) --- input/drivers_hid/iohidmanager_hid.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/input/drivers_hid/iohidmanager_hid.c b/input/drivers_hid/iohidmanager_hid.c index 4494f3cb67..3de1c01d80 100644 --- a/input/drivers_hid/iohidmanager_hid.c +++ b/input/drivers_hid/iohidmanager_hid.c @@ -495,7 +495,7 @@ static void iohidmanager_hid_device_remove(IOHIDDeviceRef device, iohidmanager_h for (i=0; islots[i].data; - if (!a) + if (!a || !hid->slots[i].connected) continue; if (a->handle == device) { @@ -517,6 +517,7 @@ static void iohidmanager_hid_device_remove(IOHIDDeviceRef device, iohidmanager_h hid->buttons[adapter->slot] = 0; memset(hid->axes[adapter->slot], 0, sizeof(hid->axes)); + hid->slots[adapter->slot].data = NULL; pad_connection_pad_deinit(&hid->slots[adapter->slot], adapter->slot); }