Fixed rare infinite rumble in HIDAPI controller driver
authorSam Lantinga <slouken@libsdl.org>
Thu, 19 Dec 2019 18:03:28 -0800
changeset 13364e0633ed9c498
parent 13363 eb09f372f3ac
child 13365 01f16d7f36cb
Fixed rare infinite rumble in HIDAPI controller driver
src/joystick/hidapi/SDL_hidapi_gamecube.c
src/joystick/hidapi/SDL_hidapi_ps4.c
src/joystick/hidapi/SDL_hidapi_switch.c
src/joystick/hidapi/SDL_hidapi_xbox360.c
src/joystick/hidapi/SDL_hidapi_xbox360w.c
src/joystick/hidapi/SDL_hidapi_xboxone.c
     1.1 --- a/src/joystick/hidapi/SDL_hidapi_gamecube.c	Thu Dec 19 18:00:08 2019 -0800
     1.2 +++ b/src/joystick/hidapi/SDL_hidapi_gamecube.c	Thu Dec 19 18:03:28 2019 -0800
     1.3 @@ -280,6 +280,9 @@
     1.4              }
     1.5              if (val && duration_ms) {
     1.6                  ctx->rumbleExpiration[i] = SDL_GetTicks() + SDL_min(duration_ms, SDL_MAX_RUMBLE_DURATION_MS);
     1.7 +                if (!ctx->rumbleExpiration[i]) {
     1.8 +                    ctx->rumbleExpiration[i] = 1;
     1.9 +                }
    1.10              } else {
    1.11                  ctx->rumbleExpiration[i] = 0;
    1.12              }
     2.1 --- a/src/joystick/hidapi/SDL_hidapi_ps4.c	Thu Dec 19 18:00:08 2019 -0800
     2.2 +++ b/src/joystick/hidapi/SDL_hidapi_ps4.c	Thu Dec 19 18:03:28 2019 -0800
     2.3 @@ -312,6 +312,9 @@
     2.4  
     2.5      if ((low_frequency_rumble || high_frequency_rumble) && duration_ms) {
     2.6          ctx->rumble_expiration = SDL_GetTicks() + SDL_min(duration_ms, SDL_MAX_RUMBLE_DURATION_MS);
     2.7 +        if (!ctx->rumble_expiration) {
     2.8 +            ctx->rumble_expiration = 1;
     2.9 +        }
    2.10      } else {
    2.11          ctx->rumble_expiration = 0;
    2.12      }
     3.1 --- a/src/joystick/hidapi/SDL_hidapi_switch.c	Thu Dec 19 18:00:08 2019 -0800
     3.2 +++ b/src/joystick/hidapi/SDL_hidapi_switch.c	Thu Dec 19 18:03:28 2019 -0800
     3.3 @@ -760,7 +760,10 @@
     3.4      }
     3.5  
     3.6      if ((low_frequency_rumble || high_frequency_rumble) && duration_ms) {
     3.7 -        ctx->m_nRumbleExpiration = SDL_GetTicks() + duration_ms;
     3.8 +        ctx->m_nRumbleExpiration = SDL_GetTicks() + SDL_min(duration_ms, SDL_MAX_RUMBLE_DURATION_MS);
     3.9 +        if (!ctx->m_nRumbleExpiration) {
    3.10 +            ctx->m_nRumbleExpiration = 1;
    3.11 +        }
    3.12      } else {
    3.13          ctx->m_nRumbleExpiration = 0;
    3.14      }
     4.1 --- a/src/joystick/hidapi/SDL_hidapi_xbox360.c	Thu Dec 19 18:00:08 2019 -0800
     4.2 +++ b/src/joystick/hidapi/SDL_hidapi_xbox360.c	Thu Dec 19 18:03:28 2019 -0800
     4.3 @@ -400,6 +400,9 @@
     4.4  
     4.5      if ((low_frequency_rumble || high_frequency_rumble) && duration_ms) {
     4.6          ctx->rumble_expiration = SDL_GetTicks() + SDL_min(duration_ms, SDL_MAX_RUMBLE_DURATION_MS);
     4.7 +        if (!ctx->rumble_expiration) {
     4.8 +            ctx->rumble_expiration = 1;
     4.9 +        }
    4.10      } else {
    4.11          ctx->rumble_expiration = 0;
    4.12      }
     5.1 --- a/src/joystick/hidapi/SDL_hidapi_xbox360w.c	Thu Dec 19 18:00:08 2019 -0800
     5.2 +++ b/src/joystick/hidapi/SDL_hidapi_xbox360w.c	Thu Dec 19 18:03:28 2019 -0800
     5.3 @@ -149,6 +149,9 @@
     5.4  
     5.5      if ((low_frequency_rumble || high_frequency_rumble) && duration_ms) {
     5.6          ctx->rumble_expiration = SDL_GetTicks() + SDL_min(duration_ms, SDL_MAX_RUMBLE_DURATION_MS);
     5.7 +        if (!ctx->rumble_expiration) {
     5.8 +            ctx->rumble_expiration = 1;
     5.9 +        }
    5.10      } else {
    5.11          ctx->rumble_expiration = 0;
    5.12      }
     6.1 --- a/src/joystick/hidapi/SDL_hidapi_xboxone.c	Thu Dec 19 18:00:08 2019 -0800
     6.2 +++ b/src/joystick/hidapi/SDL_hidapi_xboxone.c	Thu Dec 19 18:03:28 2019 -0800
     6.3 @@ -312,6 +312,9 @@
     6.4  
     6.5      if ((low_frequency_rumble || high_frequency_rumble) && duration_ms) {
     6.6          ctx->rumble_expiration = SDL_GetTicks() + SDL_min(duration_ms, SDL_MAX_RUMBLE_DURATION_MS);
     6.7 +        if (!ctx->rumble_expiration) {
     6.8 +            ctx->rumble_expiration = 1;
     6.9 +        }
    6.10      } else {
    6.11          ctx->rumble_expiration = 0;
    6.12      }