From 7341f04a12aa55ee1f412b0074284a41715b63bd Mon Sep 17 00:00:00 2001
From: Zizin13 <[EMAIL REDACTED]>
Date: Thu, 4 Jun 2026 09:07:03 -0700
Subject: [PATCH] Fix DirectInput POV handling for devices with extra hats
---
src/joystick/windows/SDL_dinputjoystick.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/src/joystick/windows/SDL_dinputjoystick.c b/src/joystick/windows/SDL_dinputjoystick.c
index e9a8527807cbc..0a940609b8e56 100644
--- a/src/joystick/windows/SDL_dinputjoystick.c
+++ b/src/joystick/windows/SDL_dinputjoystick.c
@@ -646,6 +646,10 @@ static BOOL CALLBACK EnumDevObjectsCallback(LPCDIDEVICEOBJECTINSTANCE pDeviceObj
in->ofs = DIJOFS_BUTTON(in->num);
joystick->nbuttons++;
} else if (pDeviceObject->dwType & DIDFT_POV) {
+ // DIJOYSTATE2.rgdwPOV only has room for 4 POVs, ignore any beyond that.
+ if (joystick->nhats >= 4) {
+ return DIENUM_CONTINUE;
+ }
in->type = HAT;
in->num = (Uint8)joystick->nhats;
in->ofs = DIJOFS_POV(in->num);
@@ -1070,7 +1074,7 @@ static void UpdateDINPUTJoystickState_Polled(SDL_Joystick *joystick)
break;
case HAT:
{
- Uint8 pos = TranslatePOV(state.rgdwPOV[in->ofs - DIJOFS_POV(0)]);
+ Uint8 pos = TranslatePOV(state.rgdwPOV[in->num]);
SDL_SendJoystickHat(timestamp, joystick, in->num, pos);
break;
}