SDLControllerInterface: Don't crash on unbound hat index

This commit is contained in:
Connor McLaughlin 2021-03-08 02:48:18 +10:00
parent 5fff104383
commit 5e0ebb5d5f

View file

@ -497,25 +497,28 @@ bool SDLControllerInterface::HandleJoystickHatEvent(const SDL_JoyHatEvent* event
bool processed = false; 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); if (const ButtonCallback& cb = it->hat_button_mapping[event->hat][0]; cb)
processed = true; {
} cb(event->value & SDL_HAT_UP);
if (const ButtonCallback& cb = it->hat_button_mapping[event->hat][1]; cb) processed = true;
{ }
cb(event->value & SDL_HAT_RIGHT); if (const ButtonCallback& cb = it->hat_button_mapping[event->hat][1]; cb)
processed = true; {
} cb(event->value & SDL_HAT_RIGHT);
if (const ButtonCallback& cb = it->hat_button_mapping[event->hat][2]; cb) processed = true;
{ }
cb(event->value & SDL_HAT_DOWN); if (const ButtonCallback& cb = it->hat_button_mapping[event->hat][2]; cb)
processed = true; {
} cb(event->value & SDL_HAT_DOWN);
if (const ButtonCallback& cb = it->hat_button_mapping[event->hat][3]; cb) processed = true;
{ }
cb(event->value & SDL_HAT_LEFT); if (const ButtonCallback& cb = it->hat_button_mapping[event->hat][3]; cb)
processed = true; {
cb(event->value & SDL_HAT_LEFT);
processed = true;
}
} }
return processed; return processed;