Only poll joysticks with a valid device.

Followup on 0577f8af.

When looping through configured joysticks, ignore ones that do not have
a valid open device pointer.

Also remove the use of std::get for the joystate map tuple and use
.first instead.

Signed-off-by: Rafael Kitover <rkitover@gmail.com>
This commit is contained in:
Rafael Kitover 2019-12-22 17:59:57 +00:00
parent 99cdbb8860
commit bbbe9fe73f
No known key found for this signature in database
GPG Key ID: 08AB596679D86240
1 changed files with 4 additions and 2 deletions

View File

@ -150,6 +150,8 @@ void wxSDLJoy::Poll()
if (do_poll) {
for (auto&& joy : joystate) {
if (!joy.second.dev) continue;
for (uint8_t but = 0; but < SDL_CONTROLLER_BUTTON_MAX; but++) {
auto last_state = joy.second.button[but];
auto state = SDL_GameControllerGetButton(joy.second.dev, static_cast<SDL_GameControllerButton>(but));
@ -237,8 +239,8 @@ void wxSDLJoy::Remove(int8_t joy_n)
add_all = false;
if (joy_n < 0) {
for (auto joy : joystate)
DisconnectController(std::get<0>(joy));
for (auto&& joy : joystate)
DisconnectController(joy.first);
joystate.clear();