Clamp compute LDS to the device limit and ignore unopenable gamepads

This commit is contained in:
Hamza Shakir
2026-10-03 04:21:39 +04:00
committed by nmzik
parent 8fa116eeb1
commit e6cb880adb
3 changed files with 79 additions and 3 deletions
+9 -3
View File
@@ -306,14 +306,20 @@ static void GameEventController([[maybe_unused]] const EventController& f) {
if (f.added) {
auto* pad = SDL_OpenGamepad(f.id);
EXIT_NOT_IMPLEMENTED(pad == nullptr);
if (pad == nullptr) {
LOGF("Controller: ignoring gamepad %d that could not be opened: %s\n", f.id,
SDL_GetError());
return;
}
int id = SDL_GetJoystickID(SDL_GetGamepadJoystick(pad));
Controller::Connect(id);
}
if (f.removed) {
Controller::Disconnect(f.id);
SDL_CloseGamepad(SDL_GetGamepadFromID(f.id));
if (auto* pad = SDL_GetGamepadFromID(f.id); pad != nullptr) {
Controller::Disconnect(f.id);
SDL_CloseGamepad(pad);
}
}
if (f.down || f.up) {