SDL: Fixed crash if Joy-Cons are disabled while a combined Joy-Cons controller is open

From 8ab9dc8b2b9ca32483f5cb5741ddc72ef22ba89b Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Wed, 3 Aug 2022 13:18:00 -0700
Subject: [PATCH] Fixed crash if Joy-Cons are disabled while a combined
 Joy-Cons controller is open

---
 src/joystick/hidapi/SDL_hidapijoystick.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/src/joystick/hidapi/SDL_hidapijoystick.c b/src/joystick/hidapi/SDL_hidapijoystick.c
index a7ac1f8e539..188dac0dab0 100644
--- a/src/joystick/hidapi/SDL_hidapijoystick.c
+++ b/src/joystick/hidapi/SDL_hidapijoystick.c
@@ -317,6 +317,17 @@ HIDAPI_SetupDeviceDriver(SDL_HIDAPI_Device *device)
         } else {
             enabled = device->driver->enabled;
         }
+        if (device->children) {
+            int i;
+
+            for (i = 0; i < device->num_children; ++i) {
+                SDL_HIDAPI_Device *child = device->children[i];
+                if (!child->driver || !child->driver->enabled) {
+                    enabled = SDL_FALSE;
+                    break;
+                }
+            }
+        }
         if (!enabled) {
             HIDAPI_CleanupDeviceDriver(device);
         }
@@ -813,7 +824,7 @@ HIDAPI_UpdateDeviceList(void)
         SDL_HIDAPI_Device *next = device->next;
 
         if (!device->seen ||
-            (device->driver && device->num_joysticks == 0 && !device->dev)) {
+            ((device->driver || device->children) && device->num_joysticks == 0 && !device->dev)) {
             if (device->parent) {
                 /* When a child device goes away, so does the parent */
                 int i;