Skip to content

Commit

Permalink
Fix device counting in HapticMouse and JoystickOpen routines. 0 is th…
Browse files Browse the repository at this point in the history
…e first item in the list not the last
  • Loading branch information
urkle committed Feb 6, 2014
1 parent f3e6a0a commit a09548e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
6 changes: 3 additions & 3 deletions src/haptic/darwin/SDL_syshaptic.c
Expand Up @@ -199,7 +199,7 @@ HapticByDevIndex(int device_index)

while (device_index > 0) {
SDL_assert(item != NULL);
device_index--;
--device_index;
item = item->next;
}

Expand Down Expand Up @@ -571,15 +571,15 @@ SDL_SYS_HapticOpen(SDL_Haptic * haptic)
int
SDL_SYS_HapticMouse(void)
{
int device_index = numhaptics-1;
int device_index = 0;
SDL_hapticlist_item *item;

for (item = SDL_hapticlist; item; item = item->next) {
if ((item->usagePage == kHIDPage_GenericDesktop) &&
(item->usage == kHIDUsage_GD_Mouse)) {
return device_index;
}
device_index--;
++device_index;
}

return -1;
Expand Down
2 changes: 1 addition & 1 deletion src/haptic/linux/SDL_syshaptic.c
Expand Up @@ -202,7 +202,7 @@ HapticByDevIndex(int device_index)

while (device_index > 0) {
SDL_assert(item != NULL);
device_index--;
--device_index;
item = item->next;
}

Expand Down
12 changes: 6 additions & 6 deletions src/haptic/windows/SDL_syshaptic.c
Expand Up @@ -442,7 +442,7 @@ HapticByDevIndex(int device_index)

while (device_index > 0) {
SDL_assert(item != NULL);
device_index--;
--device_index;
item = item->next;
}

Expand Down Expand Up @@ -784,15 +784,15 @@ int
SDL_SYS_HapticMouse(void)
{
SDL_hapticlist_item *item;
int index = numhaptics-1;
int index = 0;

/* Grab the first mouse haptic device we find. */
for (item = SDL_hapticlist; item != NULL; item = item->next) {
SDL_assert(index >= 0);
if (item->capabilities.dwDevType == DI8DEVCLASS_POINTER ) {
return index;
}
index--;
++index;
}

return -1;
Expand Down Expand Up @@ -855,7 +855,7 @@ int
SDL_SYS_HapticOpenFromJoystick(SDL_Haptic * haptic, SDL_Joystick * joystick)
{
SDL_hapticlist_item *item;
int index = numhaptics-1;
int index = 0;

/* Since it comes from a joystick we have to try to match it with a haptic device on our haptic list. */
if (joystick->hwdata->bXInputDevice) {
Expand All @@ -866,7 +866,7 @@ SDL_SYS_HapticOpenFromJoystick(SDL_Haptic * haptic, SDL_Joystick * joystick)
haptic->index = index;
return SDL_SYS_HapticOpenFromXInput(haptic, userid);
}
index--;
++index;
}
} else {
HRESULT idret;
Expand All @@ -883,7 +883,7 @@ SDL_SYS_HapticOpenFromJoystick(SDL_Haptic * haptic, SDL_Joystick * joystick)
haptic->index = index;
return SDL_SYS_HapticOpenFromDevice8(haptic, joystick->hwdata->InputDevice, SDL_TRUE);
}
index--;
++index;
}
}

Expand Down

0 comments on commit a09548e

Please sign in to comment.