From aeb275149a453ca99ff3e5d4c39ff14888c98960 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Mon, 1 Aug 2022 10:38:31 -0700
Subject: [PATCH] Poll DirectInput devices to get their initial state
Fixes https://github.com/libsdl-org/SDL/issues/3816
---
src/joystick/windows/SDL_dinputjoystick.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/src/joystick/windows/SDL_dinputjoystick.c b/src/joystick/windows/SDL_dinputjoystick.c
index 5122f0cae36..90219938092 100644
--- a/src/joystick/windows/SDL_dinputjoystick.c
+++ b/src/joystick/windows/SDL_dinputjoystick.c
@@ -855,6 +855,15 @@ SDL_DINPUT_JoystickOpen(SDL_Joystick * joystick, JoyStick_DeviceData *joystickde
} else if (FAILED(result)) {
return SetDIerror("IDirectInputDevice8::SetProperty", result);
}
+
+ /* Poll and wait for initial device state to be populated */
+ result = IDirectInputDevice8_Poll(joystick->hwdata->InputDevice);
+ if (result == DIERR_INPUTLOST || result == DIERR_NOTACQUIRED) {
+ IDirectInputDevice8_Acquire(joystick->hwdata->InputDevice);
+ IDirectInputDevice8_Poll(joystick->hwdata->InputDevice);
+ }
+ SDL_Delay(50);
+
return 0;
}