Fix some edge cases in XInput haptic timing.
authorRyan C. Gordon <icculus@icculus.org>
Sun, 20 Oct 2013 23:38:19 -0400
changeset 7855a022d3d782d2
parent 7854 6d79888998f5
child 7856 cb37776926ad
Fix some edge cases in XInput haptic timing.
src/haptic/windows/SDL_syshaptic.c
     1.1 --- a/src/haptic/windows/SDL_syshaptic.c	Sun Oct 20 23:08:45 2013 -0400
     1.2 +++ b/src/haptic/windows/SDL_syshaptic.c	Sun Oct 20 23:38:19 2013 -0400
     1.3 @@ -1326,8 +1326,13 @@
     1.4          SDL_LockMutex(haptic->hwdata->mutex);
     1.5          if(effect->effect.leftright.length == SDL_HAPTIC_INFINITY || iterations == SDL_HAPTIC_INFINITY) {
     1.6              haptic->hwdata->stopTicks = SDL_HAPTIC_INFINITY;
     1.7 +        } else if ((!effect->effect.leftright.length) || (!iterations)) {
     1.8 +            /* do nothing. Effect runs for zero milliseconds. */
     1.9          } else {
    1.10              haptic->hwdata->stopTicks = SDL_GetTicks() + (effect->effect.leftright.length * iterations);
    1.11 +            if ((haptic->hwdata->stopTicks == SDL_HAPTIC_INFINITY) || (haptic->hwdata->stopTicks == 0)) {
    1.12 +                haptic->hwdata->stopTicks = 1;  /* fix edge cases. */
    1.13 +            }
    1.14          }
    1.15          SDL_UnlockMutex(haptic->hwdata->mutex);
    1.16          return (XINPUTSETSTATE(haptic->hwdata->userid, vib) == ERROR_SUCCESS) ? 0 : -1;