From 7341f04a12aa55ee1f412b0074284a41715b63bd Mon Sep 17 00:00:00 2001 From: Zizin13 <162662805+Zizin13@users.noreply.github.com> 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 e9a8527807..0a940609b8 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; }