From b1362f8a427b32e01df19b48c8dd4b6599d6cc6d Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Tue, 20 Jan 2026 11:04:20 -0800
Subject: [PATCH] Fixed divide by zero handling Nintendo Switch 2 controller
---
src/joystick/hidapi/SDL_hidapi_switch2.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/src/joystick/hidapi/SDL_hidapi_switch2.c b/src/joystick/hidapi/SDL_hidapi_switch2.c
index 0f814fde0e591..a403eb4b5c5a4 100644
--- a/src/joystick/hidapi/SDL_hidapi_switch2.c
+++ b/src/joystick/hidapi/SDL_hidapi_switch2.c
@@ -1162,10 +1162,14 @@ static void HIDAPI_DriverSwitch2_HandleStatePacket(SDL_HIDAPI_Device *device, SD
ctx->sensor_ts_coeff = 10000;
ctx->gyro_coeff = 34.8f;
ctx->sensors_ready = true;
- } else {
+ } else if (coeff != 0) {
ctx->sensor_ts_coeff = 10000000000 / coeff;
ctx->gyro_coeff = 40.0f;
ctx->sensors_ready = true;
+ } else {
+ // Didn't get a valid reading, try again
+ ctx->first_sensor_timestamp = 0;
+ ctx->sample_count = 0;
}
if (ctx->sensors_ready && !ctx->sensors_enabled) {