From 96cfb6afcbcbb2e0622513b5a2d221b8d397cb59 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Sun, 20 Feb 2011 09:28:13 -0800 Subject: [PATCH] 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 | 12 ++++++++++++ src/haptic/windows/SDL_syshaptic.c | 21 ++++++++++++++++++++- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/haptic/darwin/SDL_syshaptic.c b/src/haptic/darwin/SDL_syshaptic.c index c5b1e54b9..fc1b4ef98 100644 --- a/src/haptic/darwin/SDL_syshaptic.c +++ b/src/haptic/darwin/SDL_syshaptic.c @@ -534,6 +534,18 @@ SDL_SYS_JoystickSameHaptic(SDL_Haptic * haptic, SDL_Joystick * joystick) int SDL_SYS_HapticOpenFromJoystick(SDL_Haptic * haptic, SDL_Joystick * joystick) { + int i; + for (i=0; ihwdata->ffservice)) { + haptic->index = i; + break; + } + } + if (i >= SDL_numhaptics) { + return -1; + } + return SDL_SYS_HapticOpenFromService(haptic, joystick->hwdata->ffservice); } diff --git a/src/haptic/windows/SDL_syshaptic.c b/src/haptic/windows/SDL_syshaptic.c index a41f684b2..1fb40a779 100644 --- a/src/haptic/windows/SDL_syshaptic.c +++ b/src/haptic/windows/SDL_syshaptic.c @@ -576,7 +576,26 @@ SDL_SYS_JoystickSameHaptic(SDL_Haptic * haptic, SDL_Joystick * joystick) int SDL_SYS_HapticOpenFromJoystick(SDL_Haptic * haptic, SDL_Joystick * joystick) { - int ret; + int i, ret; + HRESULT idret; + DIDEVICEINSTANCE joy_instance; + + /* Since it comes from a joystick we have to try to match it with a haptic device on our haptic list. */ + for (i=0; ihwdata->InputDevice, + &joy_instance); + if (FAILED(idret)) { + return -1; + } + if (DI_GUIDIsSame(&SDL_hapticlist[i].instance.guidInstance, + &joy_instance.guidInstance)) { + haptic->index = i; + break; + } + } + if (i >= SDL_numhaptics) { + return -1; + } /* Allocate the hwdata */ haptic->hwdata = (struct haptic_hwdata *)