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