Untested fix for bug 946 (SDL_HapticIndex returns 0 for all devices)
authorSam Lantinga <slouken@libsdl.org>
Sun, 20 Feb 2011 09:28:13 -0800
changeset 53585b330ef7b8dd
parent 5357 ea8fec220775
child 5359 d5fe4ed3a28d
Untested fix for bug 946 (SDL_HapticIndex returns 0 for all devices)

Edgar Simo 2011-02-20 09:02:31 PST

Linux uses fname, which is the name of the device path like for example
/dev/input/event3 so it shouldn't have the issue. However I can confirm that it
looks like haptic->index never gets properly set on windows. Have to look at
mac os x also. I'll see if I can fix it real quick now.
src/haptic/darwin/SDL_syshaptic.c
src/haptic/windows/SDL_syshaptic.c
     1.1 --- a/src/haptic/darwin/SDL_syshaptic.c	Sun Feb 20 09:24:02 2011 -0800
     1.2 +++ b/src/haptic/darwin/SDL_syshaptic.c	Sun Feb 20 09:28:13 2011 -0800
     1.3 @@ -534,6 +534,18 @@
     1.4  int
     1.5  SDL_SYS_HapticOpenFromJoystick(SDL_Haptic * haptic, SDL_Joystick * joystick)
     1.6  {
     1.7 +    int i;
     1.8 +    for (i=0; i<SDL_numhaptics; i++) {
     1.9 +       if (IOObjectIsEqualTo((io_object_t) SDL_hapticlist[i].dev,
    1.10 +                             joystick->hwdata->ffservice)) {
    1.11 +           haptic->index = i;
    1.12 +           break;
    1.13 +       }
    1.14 +    }
    1.15 +    if (i >= SDL_numhaptics) {
    1.16 +       return -1;
    1.17 +    }
    1.18 +
    1.19      return SDL_SYS_HapticOpenFromService(haptic, joystick->hwdata->ffservice);
    1.20  }
    1.21  
     2.1 --- a/src/haptic/windows/SDL_syshaptic.c	Sun Feb 20 09:24:02 2011 -0800
     2.2 +++ b/src/haptic/windows/SDL_syshaptic.c	Sun Feb 20 09:28:13 2011 -0800
     2.3 @@ -576,7 +576,26 @@
     2.4  int
     2.5  SDL_SYS_HapticOpenFromJoystick(SDL_Haptic * haptic, SDL_Joystick * joystick)
     2.6  {
     2.7 -    int ret;
     2.8 +    int i, ret;
     2.9 +    HRESULT idret;
    2.10 +    DIDEVICEINSTANCE joy_instance;
    2.11 +
    2.12 +    /* Since it comes from a joystick we have to try to match it with a haptic device on our haptic list. */
    2.13 +    for (i=0; i<SDL_numhaptics; i++) {
    2.14 +        idret = IDirectInputDevice2_GetDeviceInfo(joystick->hwdata->InputDevice,
    2.15 +              &joy_instance);
    2.16 +        if (FAILED(idret)) {
    2.17 +            return -1;
    2.18 +        }
    2.19 +        if (DI_GUIDIsSame(&SDL_hapticlist[i].instance.guidInstance,
    2.20 +                          &joy_instance.guidInstance)) {
    2.21 +            haptic->index = i;
    2.22 +            break;
    2.23 +        }
    2.24 +    }
    2.25 +    if (i >= SDL_numhaptics) {
    2.26 +        return -1;
    2.27 +    }
    2.28  
    2.29      /* Allocate the hwdata */
    2.30      haptic->hwdata = (struct haptic_hwdata *)