# HG changeset patch # User Edgar Simo # Date 1218009090 0 # Node ID 63ea27a96a96d451b71f0b8dde7834b32769e5e7 # Parent cdea9a70dade82dd7e0a08a2b16b0289eabc1a10 Check for capabilities at init. diff -r cdea9a70dade -r 63ea27a96a96 src/haptic/win32/SDL_syshaptic.c --- a/src/haptic/win32/SDL_syshaptic.c Wed Aug 06 07:42:42 2008 +0000 +++ b/src/haptic/win32/SDL_syshaptic.c Wed Aug 06 07:51:30 2008 +0000 @@ -57,6 +57,7 @@ { DIDEVICEINSTANCE instance; SDL_Haptic *haptic; + DIDEVCAPS capabilities; } SDL_hapticlist[MAX_HAPTICS]; @@ -67,7 +68,6 @@ { LPDIRECTINPUTDEVICE2 device; DWORD axes[3]; - DIDEVCAPS capabilities; }; @@ -169,10 +169,36 @@ static BOOL CALLBACK EnumHapticsCallback(const DIDEVICEINSTANCE * pdidInstance, VOID * pContext) { + HRESULT ret; + LPDIRECTINPUTDEVICE device; + + /* Copy the instance over, useful for creating devices. */ SDL_memcpy(&SDL_hapticlist[SDL_numhaptics].instance, pdidInstance, sizeof(DIDEVICEINSTANCE)); + + /* Open the device */ + ret = IDirectInput_CreateDevice( dinput, &instance.guidInstance, + &device, NULL ); + if (FAILED(ret)) { + /* DI_SetError("Creating DirectInput device",ret); */ + return DIENUM_CONTINUE; + } + + /* Get capabilities. */ + SDL_hapticlist[SDL_numhaptics].capabilities.dwSize = sizeof(DIDEVCAPS); + ret = IDirectInputDevice_GetCapabilities( device, + &SDL_hapticlist[SDL_numhaptics].capabilities ); + if (FAILED(ret)) { + /* DI_SetError("Getting device capabilities",ret); */ + IDirectInputDevice_Release(device); + return DIENUM_CONTINUE; + } + + /* Close up device and count it. */ + IDirectInputDevice_Release(device); SDL_numhaptics++; + /* Watch out for hard limit. */ if (SDL_numhaptics >= MAX_HAPTICS) return DIENUM_STOP; @@ -256,7 +282,6 @@ * - Release DirectInputDevice interface. * - Set cooperative level. * - Set data format. - * - Get capabilities. * - Acquire exclusiveness. * - Reset actuators. * - Get supported featuers. @@ -313,15 +338,6 @@ goto query_err; } - /* Get capabilities. */ - haptic->hwdata->capabilities.dwSize = sizeof(DIDEVCAPS); - ret = IDirectInputDevice2_GetCapabilities( haptic->hwdata->device, - &haptic->hwdata->capabilities ); - if (FAILED(ret)) { - DI_SetError("Getting device capabilities",ret); - goto acquire_err; - } - /* Get number of axes. */ ret = IDirectInputDevice2_EnumObjects( haptic->hwdata->device, DI_DeviceObjectCallback, @@ -435,6 +451,10 @@ int SDL_SYS_HapticMouse(void) { + int i; + + for (i=0; i