Fix SDL gyro and acceleration sensor handling (#2532)

* Fix sensor handling if they are enabled but an error was thrown regardless

* Initialise orientation to a default value + clang
This commit is contained in:
kalaposfos13 2025-02-24 21:38:06 +01:00 committed by GitHub
parent fd3bfdae80
commit b8aac357cb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 17 additions and 11 deletions

View file

@ -134,13 +134,17 @@ void SDLInputEngine::Init() {
m_gyro_poll_rate = SDL_GetGamepadSensorDataRate(m_gamepad, SDL_SENSOR_GYRO);
LOG_INFO(Input, "Gyro initialized, poll rate: {}", m_gyro_poll_rate);
} else {
LOG_ERROR(Input, "Failed to initialize gyro controls for gamepad");
LOG_ERROR(Input, "Failed to initialize gyro controls for gamepad, error: {}",
SDL_GetError());
SDL_SetGamepadSensorEnabled(m_gamepad, SDL_SENSOR_GYRO, false);
}
if (SDL_SetGamepadSensorEnabled(m_gamepad, SDL_SENSOR_ACCEL, true)) {
m_accel_poll_rate = SDL_GetGamepadSensorDataRate(m_gamepad, SDL_SENSOR_ACCEL);
LOG_INFO(Input, "Accel initialized, poll rate: {}", m_accel_poll_rate);
} else {
LOG_ERROR(Input, "Failed to initialize accel controls for gamepad");
LOG_ERROR(Input, "Failed to initialize accel controls for gamepad, error: {}",
SDL_GetError());
SDL_SetGamepadSensorEnabled(m_gamepad, SDL_SENSOR_ACCEL, false);
}
}