From 3b6f122830d31087f8717c3f9032a32dafdd6e8f 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
(cherry picked from commit 7341f04a12aa55ee1f412b0074284a41715b63bd)
---
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 62ffbb46ec9fa..c6712600f8dc1 100644
--- a/src/joystick/windows/SDL_dinputjoystick.c
+++ b/src/joystick/windows/SDL_dinputjoystick.c
@@ -644,6 +644,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);
@@ -1068,7 +1072,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;
}