Fix device counting in HapticMouse and JoystickOpen routines. 0 is the first item in the list not the last
authorEdward Rudd <urkle@outoforder.cc>
Thu, 06 Feb 2014 09:35:44 -0500
changeset 8183f8404b0e00ac
parent 8182 92f71edde3be
child 8184 2afb90ff0199
Fix device counting in HapticMouse and JoystickOpen routines. 0 is the first item in the list not the last
src/haptic/darwin/SDL_syshaptic.c
src/haptic/linux/SDL_syshaptic.c
src/haptic/windows/SDL_syshaptic.c
     1.1 --- a/src/haptic/darwin/SDL_syshaptic.c	Thu Feb 06 09:11:05 2014 -0500
     1.2 +++ b/src/haptic/darwin/SDL_syshaptic.c	Thu Feb 06 09:35:44 2014 -0500
     1.3 @@ -199,7 +199,7 @@
     1.4  
     1.5      while (device_index > 0) {
     1.6          SDL_assert(item != NULL);
     1.7 -        device_index--;
     1.8 +        --device_index;
     1.9          item = item->next;
    1.10      }
    1.11  
    1.12 @@ -571,7 +571,7 @@
    1.13  int
    1.14  SDL_SYS_HapticMouse(void)
    1.15  {
    1.16 -    int device_index = numhaptics-1;
    1.17 +    int device_index = 0;
    1.18      SDL_hapticlist_item *item;
    1.19  
    1.20      for (item = SDL_hapticlist; item; item = item->next) {
    1.21 @@ -579,7 +579,7 @@
    1.22              (item->usage == kHIDUsage_GD_Mouse)) {
    1.23              return device_index;
    1.24          }
    1.25 -        device_index--;
    1.26 +        ++device_index;
    1.27      }
    1.28  
    1.29      return -1;
     2.1 --- a/src/haptic/linux/SDL_syshaptic.c	Thu Feb 06 09:11:05 2014 -0500
     2.2 +++ b/src/haptic/linux/SDL_syshaptic.c	Thu Feb 06 09:35:44 2014 -0500
     2.3 @@ -202,7 +202,7 @@
     2.4  
     2.5      while (device_index > 0) {
     2.6          SDL_assert(item != NULL);
     2.7 -        device_index--;
     2.8 +        --device_index;
     2.9          item = item->next;
    2.10      }
    2.11  
     3.1 --- a/src/haptic/windows/SDL_syshaptic.c	Thu Feb 06 09:11:05 2014 -0500
     3.2 +++ b/src/haptic/windows/SDL_syshaptic.c	Thu Feb 06 09:35:44 2014 -0500
     3.3 @@ -442,7 +442,7 @@
     3.4  
     3.5      while (device_index > 0) {
     3.6          SDL_assert(item != NULL);
     3.7 -        device_index--;
     3.8 +        --device_index;
     3.9          item = item->next;
    3.10      }
    3.11  
    3.12 @@ -784,7 +784,7 @@
    3.13  SDL_SYS_HapticMouse(void)
    3.14  {
    3.15      SDL_hapticlist_item *item;
    3.16 -    int index = numhaptics-1;
    3.17 +    int index = 0;
    3.18  
    3.19      /* Grab the first mouse haptic device we find. */
    3.20      for (item = SDL_hapticlist; item != NULL; item = item->next) {
    3.21 @@ -792,7 +792,7 @@
    3.22          if (item->capabilities.dwDevType == DI8DEVCLASS_POINTER ) {
    3.23              return index;
    3.24          }
    3.25 -        index--;
    3.26 +        ++index;
    3.27      }
    3.28  
    3.29      return -1;
    3.30 @@ -855,7 +855,7 @@
    3.31  SDL_SYS_HapticOpenFromJoystick(SDL_Haptic * haptic, SDL_Joystick * joystick)
    3.32  {
    3.33      SDL_hapticlist_item *item;
    3.34 -    int index = numhaptics-1;
    3.35 +    int index = 0;
    3.36  
    3.37      /* Since it comes from a joystick we have to try to match it with a haptic device on our haptic list. */
    3.38      if (joystick->hwdata->bXInputDevice) {
    3.39 @@ -866,7 +866,7 @@
    3.40                  haptic->index = index;
    3.41                  return SDL_SYS_HapticOpenFromXInput(haptic, userid);
    3.42              }
    3.43 -            index--;
    3.44 +            ++index;
    3.45          }
    3.46      } else {
    3.47          HRESULT idret;
    3.48 @@ -883,7 +883,7 @@
    3.49                  haptic->index = index;
    3.50                  return SDL_SYS_HapticOpenFromDevice8(haptic, joystick->hwdata->InputDevice, SDL_TRUE);
    3.51              }
    3.52 -            index--;
    3.53 +            ++index;
    3.54          }
    3.55      }
    3.56