question

Jacob-9015 avatar image
0 Votes"
Jacob-9015 asked Jacob-9015 edited

How to safely read Gamepads() vector view

winrt::Windows::Gaming::Input::Gamepad::Gamepads() returns an IVectorView of all connected Gamepads, which can change at any time as controllers are connected and disconnected from the user's computer. What is the correct way to access the vector as to not cause a race condition?

windows-uwp
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@Jacob-9015 You could register handlers for GamepadAdded and GamepadRemoved events to keep track the gamepads that are currently connected. Then you could refer to the official sample to check the m_currentGamepadNeedsRefresh variable to get these changed gamepads, so that you could get the specified vector view for these not changed gamepads.

0 Votes 0 ·

0 Answers