[Commits] SDL: Fixed crash launching under Steam on Mac OS X

libsdl.org revision control commits-owner at libsdl.org
Fri Sep 14 12:41:32 PDT 2018


details:   https://hg.libsdl.org/SDL/rev/b6aa21d1a522
changeset: 12185:b6aa21d1a522
user:      Sam Lantinga <slouken at libsdl.org>
date:      Fri Sep 14 12:41:29 2018 -0700
description:
Fixed crash launching under Steam on Mac OS X

diffstat:

 src/joystick/SDL_gamecontroller.c        |   5 +++--
 src/joystick/hidapi/SDL_hidapijoystick.c |  21 ++++++++++++---------
 2 files changed, 15 insertions(+), 11 deletions(-)

diffs (75 lines):

diff -r 02509665751f -r b6aa21d1a522 src/joystick/SDL_gamecontroller.c
--- a/src/joystick/SDL_gamecontroller.c	Mon Sep 10 23:01:33 2018 -0700
+++ b/src/joystick/SDL_gamecontroller.c	Fri Sep 14 12:41:29 2018 -0700
@@ -1462,6 +1462,7 @@
     int i;
     Uint16 vendor;
     Uint16 product;
+    Uint16 version;
     Uint32 vidpid;
 
     if (SDL_allowed_controllers.num_entries == 0 &&
@@ -1469,7 +1470,7 @@
         return SDL_FALSE;
     }
 
-    SDL_GetJoystickGUIDInfo(guid, &vendor, &product, NULL);
+    SDL_GetJoystickGUIDInfo(guid, &vendor, &product, &version);
 
     if (SDL_GetHintBoolean("SDL_GAMECONTROLLER_ALLOW_STEAM_VIRTUAL_GAMEPAD", SDL_FALSE)) {
         /* We shouldn't ignore Steam's virtual gamepad since it's using the hints to filter out the real controllers so it can remap input for the virtual controller */
@@ -1477,7 +1478,7 @@
 #if defined(__LINUX__)
         bSteamVirtualGamepad = (vendor == 0x28DE && product == 0x11FF);
 #elif defined(__MACOSX__)
-        bSteamVirtualGamepad = (SDL_strncmp(name, "GamePad-", 8) == 0);
+        bSteamVirtualGamepad = (vendor == 0x045E && product == 0x028E && version == 1);
 #elif defined(__WIN32__)
         /* We can't tell on Windows, but Steam will block others in input hooks */
         bSteamVirtualGamepad = SDL_TRUE;
diff -r 02509665751f -r b6aa21d1a522 src/joystick/hidapi/SDL_hidapijoystick.c
--- a/src/joystick/hidapi/SDL_hidapijoystick.c	Mon Sep 10 23:01:33 2018 -0700
+++ b/src/joystick/hidapi/SDL_hidapijoystick.c	Fri Sep 14 12:41:29 2018 -0700
@@ -736,15 +736,8 @@
         device->guid.data[14] = 'h';
         device->guid.data[15] = 0;
     }
-    device->driver = HIDAPI_GetDeviceDriver(device);
 
-    if (device->driver) {
-        const char *name = device->driver->GetDeviceName(device->vendor_id, device->product_id);
-        if (name) {
-            device->name = SDL_strdup(name);
-        }
-    }
-
+    /* Need the device name before getting the driver to know whether to ignore this device */
     if (!device->name && info->manufacturer_string && info->product_string) {
         char *manufacturer_string = SDL_iconv_string("UTF-8", "WCHAR_T", (char*)info->manufacturer_string, (SDL_wcslen(info->manufacturer_string)+1)*sizeof(wchar_t));
         char *product_string = SDL_iconv_string("UTF-8", "WCHAR_T", (char*)info->product_string, (SDL_wcslen(info->product_string)+1)*sizeof(wchar_t));
@@ -781,6 +774,16 @@
         SDL_snprintf(device->name, name_size, "0x%.4x/0x%.4x", info->vendor_id, info->product_id);
     }
 
+    device->driver = HIDAPI_GetDeviceDriver(device);
+
+    if (device->driver) {
+        const char *name = device->driver->GetDeviceName(device->vendor_id, device->product_id);
+        if (name) {
+            SDL_free(device->name);
+            device->name = SDL_strdup(name);
+        }
+    }
+
     device->path = SDL_strdup(info->path);
     if (!device->path) {
         SDL_free(device->name);
@@ -789,7 +792,7 @@
     }
 
 #ifdef DEBUG_HIDAPI
-    SDL_Log("Adding HIDAPI device '%s' VID 0x%.4x, PID 0x%.4x, version %d, interface %d, usage page 0x%.4x, usage 0x%.4x\n", device->name, device->vendor_id, device->product_id, device->version, device->interface_number, device->usage_page, device->usage);
+    SDL_Log("Adding HIDAPI device '%s' VID 0x%.4x, PID 0x%.4x, version %d, interface %d, usage page 0x%.4x, usage 0x%.4x, driver = %s\n", device->name, device->vendor_id, device->product_id, device->version, device->interface_number, device->usage_page, device->usage, device->driver ? device->driver->hint : "NONE");
 #endif
 
     /* Add it to the list */


More information about the commits mailing list