Only allocate a joystick instance ID once we know it's a joystick.
authorSam Lantinga <slouken@libsdl.org>
Sun, 06 Oct 2013 20:39:23 -0700
changeset 7791d9f0067a5421
parent 7790 8136ce6b3950
child 7792 b8d4be87970a
Only allocate a joystick instance ID once we know it's a joystick.
This fixes compatibility with code that assumes 0 based joystick instance IDs.
src/joystick/darwin/SDL_sysjoystick.c
     1.1 --- a/src/joystick/darwin/SDL_sysjoystick.c	Sun Oct 06 13:50:36 2013 -0700
     1.2 +++ b/src/joystick/darwin/SDL_sysjoystick.c	Sun Oct 06 20:39:23 2013 -0700
     1.3 @@ -589,7 +589,6 @@
     1.4              if (kIOReturnSuccess == result) {
     1.5                  HIDGetDeviceInfo(hidDevice, hidProperties, pDevice);    /* hidDevice used to find parents in registry tree */
     1.6                  HIDGetCollectionElements(hidProperties, pDevice);
     1.7 -                pDevice->instance_id = ++s_joystick_instance_id;
     1.8              } else {
     1.9                  DisposePtr((Ptr) pDevice);
    1.10                  pDevice = NULL;
    1.11 @@ -678,6 +677,9 @@
    1.12          return 0;
    1.13      }
    1.14  
    1.15 +    /* Allocate an instance ID for this device */
    1.16 +    device->instance_id = ++s_joystick_instance_id;
    1.17 +
    1.18      /* We have to do some storage of the io_service_t for
    1.19       * SDL_HapticOpenFromJoystick */
    1.20      if (FFIsForceFeedback(ioHIDDeviceObject) == FF_OK) {