Skip to content

Commit

Permalink
SDLControllerInterface: Don't crash on unbound hat index
Browse files Browse the repository at this point in the history
  • Loading branch information
stenzek committed Mar 7, 2021
1 parent 5fff104 commit 5e0ebb5
Showing 1 changed file with 21 additions and 18 deletions.
39 changes: 21 additions & 18 deletions src/frontend-common/sdl_controller_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -497,25 +497,28 @@ bool SDLControllerInterface::HandleJoystickHatEvent(const SDL_JoyHatEvent* event

bool processed = false;

if (const ButtonCallback& cb = it->hat_button_mapping[event->hat][0]; cb)
if (event->hat < it->hat_button_mapping.size())
{
cb(event->value & SDL_HAT_UP);
processed = true;
}
if (const ButtonCallback& cb = it->hat_button_mapping[event->hat][1]; cb)
{
cb(event->value & SDL_HAT_RIGHT);
processed = true;
}
if (const ButtonCallback& cb = it->hat_button_mapping[event->hat][2]; cb)
{
cb(event->value & SDL_HAT_DOWN);
processed = true;
}
if (const ButtonCallback& cb = it->hat_button_mapping[event->hat][3]; cb)
{
cb(event->value & SDL_HAT_LEFT);
processed = true;
if (const ButtonCallback& cb = it->hat_button_mapping[event->hat][0]; cb)
{
cb(event->value & SDL_HAT_UP);
processed = true;
}
if (const ButtonCallback& cb = it->hat_button_mapping[event->hat][1]; cb)
{
cb(event->value & SDL_HAT_RIGHT);
processed = true;
}
if (const ButtonCallback& cb = it->hat_button_mapping[event->hat][2]; cb)
{
cb(event->value & SDL_HAT_DOWN);
processed = true;
}
if (const ButtonCallback& cb = it->hat_button_mapping[event->hat][3]; cb)
{
cb(event->value & SDL_HAT_LEFT);
processed = true;
}
}

return processed;
Expand Down

0 comments on commit 5e0ebb5

Please sign in to comment.