Skip to content

Commit

Permalink
Fixed crash launching under Steam on Mac OS X
Browse files Browse the repository at this point in the history
  • Loading branch information
slouken committed Sep 14, 2018
1 parent 0b3a350 commit 6a7b0c2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
5 changes: 3 additions & 2 deletions src/joystick/SDL_gamecontroller.c
Expand Up @@ -1462,22 +1462,23 @@ SDL_bool SDL_ShouldIgnoreGameController(const char *name, SDL_JoystickGUID guid)
int i;
Uint16 vendor;
Uint16 product;
Uint16 version;
Uint32 vidpid;

if (SDL_allowed_controllers.num_entries == 0 &&
SDL_ignored_controllers.num_entries == 0) {
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 */
SDL_bool bSteamVirtualGamepad = SDL_FALSE;
#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;
Expand Down
21 changes: 12 additions & 9 deletions src/joystick/hidapi/SDL_hidapijoystick.c
Expand Up @@ -736,15 +736,8 @@ HIDAPI_AddDevice(struct hid_device_info *info)
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));
Expand Down Expand Up @@ -781,6 +774,16 @@ HIDAPI_AddDevice(struct hid_device_info *info)
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);
Expand All @@ -789,7 +792,7 @@ HIDAPI_AddDevice(struct hid_device_info *info)
}

#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 */
Expand Down

0 comments on commit 6a7b0c2

Please sign in to comment.