mirror of
https://github.com/libsdl-org/SDL.git
synced 2026-06-05 22:30:29 +00:00
joystick: Fix underflow with 0 delta timestamp
Some sensors will occasionally report two identical timestamps in a row.
This leads to the timestamp wrapping calculation to underflow, subtracting
0x80000000 from the timestamp whenever it happens. By adjusting the wrap
test, we can just directly add zero to the timestamp, fixing the underflow.
(cherry picked from commit 687a59f277)
This commit is contained in:
parent
11cb97888b
commit
30c2648fbe
5 changed files with 5 additions and 5 deletions
|
|
@ -595,7 +595,7 @@ static void HIDAPI_Driver8BitDo_HandleStatePacket(SDL_Joystick *joystick, SDL_Dr
|
|||
Uint32 tick = LOAD32(data[27], data[28], data[29], data[30]);
|
||||
|
||||
if (ctx->last_tick) {
|
||||
if (ctx->last_tick < tick) {
|
||||
if (ctx->last_tick <= tick) {
|
||||
delta = (tick - ctx->last_tick);
|
||||
} else {
|
||||
delta = (SDL_MAX_UINT32 - ctx->last_tick + tick + 1);
|
||||
|
|
|
|||
|
|
@ -1150,7 +1150,7 @@ static void HIDAPI_DriverPS4_HandleStatePacket(SDL_Joystick *joystick, SDL_hid_d
|
|||
float data[3];
|
||||
|
||||
tick = LOAD16(packet->rgucTimestamp[0], packet->rgucTimestamp[1]);
|
||||
if (ctx->last_tick < tick) {
|
||||
if (ctx->last_tick <= tick) {
|
||||
delta = (tick - ctx->last_tick);
|
||||
} else {
|
||||
delta = (SDL_MAX_UINT16 - ctx->last_tick + tick + 1);
|
||||
|
|
|
|||
|
|
@ -1364,7 +1364,7 @@ static void HIDAPI_DriverPS5_HandleStatePacketCommon(SDL_Joystick *joystick, SDL
|
|||
Uint32 delta;
|
||||
Uint16 tick = LOAD16(packet->rgucSensorTimestamp[0],
|
||||
packet->rgucSensorTimestamp[1]);
|
||||
if (ctx->last_tick < tick) {
|
||||
if (ctx->last_tick <= tick) {
|
||||
delta = (tick - ctx->last_tick);
|
||||
} else {
|
||||
delta = (SDL_MAX_UINT16 - ctx->last_tick + tick + 1);
|
||||
|
|
|
|||
|
|
@ -307,7 +307,7 @@ static void HIDAPI_DriverSteamHori_HandleStatePacket(SDL_Joystick *joystick, SDL
|
|||
Uint32 delta;
|
||||
Uint16 tick = LOAD16(data[10],
|
||||
data[11]);
|
||||
if (ctx->last_tick < tick) {
|
||||
if (ctx->last_tick <= tick) {
|
||||
delta = (tick - ctx->last_tick);
|
||||
} else {
|
||||
delta = (SDL_MAX_UINT16 - ctx->last_tick + tick + 1);
|
||||
|
|
|
|||
|
|
@ -2086,7 +2086,7 @@ static void HandleInputEvents(SDL_Joystick *joystick)
|
|||
if (code == MSC_TIMESTAMP) {
|
||||
Sint32 tick = event->value;
|
||||
Sint32 delta;
|
||||
if (joystick->hwdata->last_tick < tick) {
|
||||
if (joystick->hwdata->last_tick <= tick) {
|
||||
delta = (tick - joystick->hwdata->last_tick);
|
||||
} else {
|
||||
delta = (SDL_MAX_SINT32 - joystick->hwdata->last_tick + tick + 1);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue