Fixed crash launching under Steam on Mac OS X
authorSam Lantinga <slouken@libsdl.org>
Fri, 14 Sep 2018 12:41:29 -0700
changeset 12185b6aa21d1a522
parent 12184 02509665751f
child 12186 6e9555603dc5
Fixed crash launching under Steam on Mac OS X
src/joystick/SDL_gamecontroller.c
src/joystick/hidapi/SDL_hidapijoystick.c
     1.1 --- a/src/joystick/SDL_gamecontroller.c	Mon Sep 10 23:01:33 2018 -0700
     1.2 +++ b/src/joystick/SDL_gamecontroller.c	Fri Sep 14 12:41:29 2018 -0700
     1.3 @@ -1462,6 +1462,7 @@
     1.4      int i;
     1.5      Uint16 vendor;
     1.6      Uint16 product;
     1.7 +    Uint16 version;
     1.8      Uint32 vidpid;
     1.9  
    1.10      if (SDL_allowed_controllers.num_entries == 0 &&
    1.11 @@ -1469,7 +1470,7 @@
    1.12          return SDL_FALSE;
    1.13      }
    1.14  
    1.15 -    SDL_GetJoystickGUIDInfo(guid, &vendor, &product, NULL);
    1.16 +    SDL_GetJoystickGUIDInfo(guid, &vendor, &product, &version);
    1.17  
    1.18      if (SDL_GetHintBoolean("SDL_GAMECONTROLLER_ALLOW_STEAM_VIRTUAL_GAMEPAD", SDL_FALSE)) {
    1.19          /* 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 */
    1.20 @@ -1477,7 +1478,7 @@
    1.21  #if defined(__LINUX__)
    1.22          bSteamVirtualGamepad = (vendor == 0x28DE && product == 0x11FF);
    1.23  #elif defined(__MACOSX__)
    1.24 -        bSteamVirtualGamepad = (SDL_strncmp(name, "GamePad-", 8) == 0);
    1.25 +        bSteamVirtualGamepad = (vendor == 0x045E && product == 0x028E && version == 1);
    1.26  #elif defined(__WIN32__)
    1.27          /* We can't tell on Windows, but Steam will block others in input hooks */
    1.28          bSteamVirtualGamepad = SDL_TRUE;
     2.1 --- a/src/joystick/hidapi/SDL_hidapijoystick.c	Mon Sep 10 23:01:33 2018 -0700
     2.2 +++ b/src/joystick/hidapi/SDL_hidapijoystick.c	Fri Sep 14 12:41:29 2018 -0700
     2.3 @@ -736,15 +736,8 @@
     2.4          device->guid.data[14] = 'h';
     2.5          device->guid.data[15] = 0;
     2.6      }
     2.7 -    device->driver = HIDAPI_GetDeviceDriver(device);
     2.8  
     2.9 -    if (device->driver) {
    2.10 -        const char *name = device->driver->GetDeviceName(device->vendor_id, device->product_id);
    2.11 -        if (name) {
    2.12 -            device->name = SDL_strdup(name);
    2.13 -        }
    2.14 -    }
    2.15 -
    2.16 +    /* Need the device name before getting the driver to know whether to ignore this device */
    2.17      if (!device->name && info->manufacturer_string && info->product_string) {
    2.18          char *manufacturer_string = SDL_iconv_string("UTF-8", "WCHAR_T", (char*)info->manufacturer_string, (SDL_wcslen(info->manufacturer_string)+1)*sizeof(wchar_t));
    2.19          char *product_string = SDL_iconv_string("UTF-8", "WCHAR_T", (char*)info->product_string, (SDL_wcslen(info->product_string)+1)*sizeof(wchar_t));
    2.20 @@ -781,6 +774,16 @@
    2.21          SDL_snprintf(device->name, name_size, "0x%.4x/0x%.4x", info->vendor_id, info->product_id);
    2.22      }
    2.23  
    2.24 +    device->driver = HIDAPI_GetDeviceDriver(device);
    2.25 +
    2.26 +    if (device->driver) {
    2.27 +        const char *name = device->driver->GetDeviceName(device->vendor_id, device->product_id);
    2.28 +        if (name) {
    2.29 +            SDL_free(device->name);
    2.30 +            device->name = SDL_strdup(name);
    2.31 +        }
    2.32 +    }
    2.33 +
    2.34      device->path = SDL_strdup(info->path);
    2.35      if (!device->path) {
    2.36          SDL_free(device->name);
    2.37 @@ -789,7 +792,7 @@
    2.38      }
    2.39  
    2.40  #ifdef DEBUG_HIDAPI
    2.41 -    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);
    2.42 +    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");
    2.43  #endif
    2.44  
    2.45      /* Add it to the list */