Browse Source

Poll DirectInput devices to get their initial state

Fixes https://github.com/libsdl-org/SDL/issues/3816
Sam Lantinga 3 years ago
parent
commit
aeb275149a
1 changed files with 9 additions and 0 deletions
  1. 9 0
      src/joystick/windows/SDL_dinputjoystick.c

+ 9 - 0
src/joystick/windows/SDL_dinputjoystick.c

@@ -855,6 +855,15 @@ SDL_DINPUT_JoystickOpen(SDL_Joystick * joystick, JoyStick_DeviceData *joystickde
     } else if (FAILED(result)) {
     } else if (FAILED(result)) {
         return SetDIerror("IDirectInputDevice8::SetProperty", 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;
     return 0;
 }
 }