Fixed crash trying to open HIDAPI controller as a haptics device on Windows
authorSam Lantinga <slouken@libsdl.org>
Wed, 22 Aug 2018 17:44:28 -0700
changeset 12142b2123abf97e0
parent 12141 6b61de046a2f
child 12143 673ec0369266
Fixed crash trying to open HIDAPI controller as a haptics device on Windows
Android.mk
Xcode-iOS/Test/TestiPhoneOS.xcodeproj/project.pbxproj
Xcode/SDLTest/SDLTest.xcodeproj/project.pbxproj
src/haptic/windows/SDL_windowshaptic.c
     1.1 --- a/src/haptic/windows/SDL_windowshaptic.c	Tue Aug 21 20:46:25 2018 -0700
     1.2 +++ b/src/haptic/windows/SDL_windowshaptic.c	Wed Aug 22 17:44:28 2018 -0700
     1.3 @@ -157,7 +157,7 @@
     1.4  
     1.5      /* Grab the first mouse haptic device we find. */
     1.6      for (item = SDL_hapticlist; item != NULL; item = item->next) {
     1.7 -        if (item->capabilities.dwDevType == DI8DEVCLASS_POINTER ) {
     1.8 +        if (item->capabilities.dwDevType == DI8DEVCLASS_POINTER) {
     1.9              return index;
    1.10          }
    1.11          ++index;
    1.12 @@ -173,14 +173,16 @@
    1.13  int
    1.14  SDL_SYS_JoystickIsHaptic(SDL_Joystick * joystick)
    1.15  {
    1.16 -    const struct joystick_hwdata *hwdata = joystick->hwdata;
    1.17 +    if (joystick->driver != &SDL_WINDOWS_JoystickDriver) {
    1.18 +        return 0;
    1.19 +    }
    1.20  #if SDL_HAPTIC_XINPUT
    1.21 -    if (hwdata->bXInputHaptic) {
    1.22 +    if (joystick->hwdata->bXInputHaptic) {
    1.23          return 1;
    1.24      }
    1.25  #endif
    1.26  #if SDL_HAPTIC_DINPUT
    1.27 -    if (hwdata->Capabilities.dwFlags & DIDC_FORCEFEEDBACK) {
    1.28 +    if (joystick->hwdata->Capabilities.dwFlags & DIDC_FORCEFEEDBACK) {
    1.29          return 1;
    1.30      }
    1.31  #endif
    1.32 @@ -193,6 +195,9 @@
    1.33  int
    1.34  SDL_SYS_JoystickSameHaptic(SDL_Haptic * haptic, SDL_Joystick * joystick)
    1.35  {
    1.36 +    if (joystick->driver != &SDL_WINDOWS_JoystickDriver) {
    1.37 +        return 0;
    1.38 +    }
    1.39      if (joystick->hwdata->bXInputHaptic != haptic->hwdata->bXInputHaptic) {
    1.40          return 0;  /* one is XInput, one is not; not the same device. */
    1.41      } else if (joystick->hwdata->bXInputHaptic) {
    1.42 @@ -208,6 +213,8 @@
    1.43  int
    1.44  SDL_SYS_HapticOpenFromJoystick(SDL_Haptic * haptic, SDL_Joystick * joystick)
    1.45  {
    1.46 +    SDL_assert(joystick->driver == &SDL_WINDOWS_JoystickDriver);
    1.47 +
    1.48      if (joystick->hwdata->bXInputDevice) {
    1.49          return SDL_XINPUT_HapticOpenFromJoystick(haptic, joystick);
    1.50      } else {