Skip to content

Commit

Permalink
Mac: Don't add the same joystick twice if IOKit reports a duplicate d…
Browse files Browse the repository at this point in the history
…evice.

Fixes Bugzilla #2704.
  • Loading branch information
icculus committed Aug 31, 2014
1 parent 7e51596 commit 724d24d
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/joystick/darwin/SDL_sysjoystick.c
Expand Up @@ -364,15 +364,33 @@ GetDeviceInfo(IOHIDDeviceRef hidDevice, recDevice *pDevice)
return SDL_TRUE;
}

static SDL_bool
JoystickAlreadyKnown(IOHIDDeviceRef ioHIDDeviceObject)
{
recDevice *i;
for (i = gpDeviceList; i != NULL; i = i->pNext) {
if (i->deviceRef == ioHIDDeviceObject) {
return SDL_TRUE;
}
}
return SDL_FALSE;
}


static void
JoystickDeviceWasAddedCallback(void *ctx, IOReturn res, void *sender, IOHIDDeviceRef ioHIDDeviceObject)
{
recDevice *device;

if (res != kIOReturnSuccess) {
return;
}

recDevice *device = (recDevice *) SDL_calloc(1, sizeof(recDevice));
if (JoystickAlreadyKnown(ioHIDDeviceObject)) {
return; /* IOKit sent us a duplicate. */
}

device = (recDevice *) SDL_calloc(1, sizeof(recDevice));

if (!device) {
SDL_OutOfMemory();
Expand Down

0 comments on commit 724d24d

Please sign in to comment.