diff --git a/src/input_common/input_common.cpp b/src/input_common/input_common.cpp index 2fb898c31..2afe9fe6b 100644 --- a/src/input_common/input_common.cpp +++ b/src/input_common/input_common.cpp @@ -26,9 +26,7 @@ static u64 frame_ticks; static void InputCallback(u64 userdata, int cycles_late) { // Call user input plugin Poll() - if (g_user_input != nullptr) { - g_user_input->Poll(); - } + if (g_user_input != nullptr) g_user_input->Poll(); // Reschedule recurrent event CoreTiming::ScheduleEvent(frame_ticks - cycles_late, input_event); diff --git a/src/input_common/input_common.h b/src/input_common/input_common.h index 14c588b00..7c690f3eb 100644 --- a/src/input_common/input_common.h +++ b/src/input_common/input_common.h @@ -55,6 +55,6 @@ void Init(ControllerBackends backend); void Shutdown(); /// InputCommon 'plugin' -extern std::unique_ptr g_user_input; +extern ControllerBase* g_user_input; } // namespace diff --git a/src/input_common/sdl_input/sdl_input.cpp b/src/input_common/sdl_input/sdl_input.cpp index c0e9c2147..1b18ce0ad 100644 --- a/src/input_common/sdl_input/sdl_input.cpp +++ b/src/input_common/sdl_input/sdl_input.cpp @@ -9,7 +9,7 @@ namespace InputCommon { SDLController::SDLController() { - device_name = "SDL2::NONE"; + device_name = "SDL2::"; jpad = nullptr; index = 0; @@ -29,6 +29,7 @@ bool SDLController::Init() { // Attempt to initialize SDL with joystick only if (SDL_Init(SDL_INIT_JOYSTICK) != 0) { + Shutdown(); return false; } @@ -37,10 +38,12 @@ bool SDLController::Init() { jpad = SDL_JoystickOpen(index); if (jpad == nullptr) { + Shutdown(); return false; } - device_name = SDL_JoystickNameForIndex(index); + std::string index_name = SDL_JoystickNameForIndex(index); + device_name += index_name; // If joystick successfully opened, load up keymap from input configuration // TODO - Make it NOT hardcoded @@ -57,9 +60,8 @@ void SDLController::DiscoverDevices() {} void SDLController::Shutdown() { // Attempt to close joystick with SDL - if (jpad != nullptr) { - SDL_JoystickClose(jpad); - } + if (jpad != nullptr) SDL_JoystickClose(jpad); + SDL_Quit(); } void SDLController::Poll() { @@ -233,4 +235,4 @@ bool SDLController::CheckDeadZone(int range) const { return false; } -}// namespace +} // namespace