diff --git a/src/input_common/input_common.cpp b/src/input_common/input_common.cpp index db3480281..d0af6ea39 100644 --- a/src/input_common/input_common.cpp +++ b/src/input_common/input_common.cpp @@ -41,8 +41,7 @@ const Service::HID::PadState ControllerBase::GetPadState() const { } void Init(ControllerBackends backend) { - switch(backend) - { + switch(backend) { //SDL2 backend selected case SDL2_JOY: g_user_input = new SDLController(); @@ -57,6 +56,12 @@ void Init(ControllerBackends backend) { break; } + //Shutdown immediately if backend failed to initialize + if((g_user_input != nullptr) && (!g_user_input->activated)) { + ShutDown(); + return; + } + //Setup CoreTiming frame_ticks = 268123480 / Settings::values.gpu_refresh_rate / 16; @@ -65,9 +70,7 @@ void Init(ControllerBackends backend) { } void ShutDown() { - //Delete the current user input plugin - if(g_user_input != nullptr) - { + if((g_user_input != nullptr) delete g_user_input; g_user_input = nullptr; } diff --git a/src/input_common/input_common.h b/src/input_common/input_common.h index 5126f0b72..aab75267f 100644 --- a/src/input_common/input_common.h +++ b/src/input_common/input_common.h @@ -38,6 +38,8 @@ public: ///Returns internal pad state const Service::HID::PadState GetPadState() const; + bool activated; + protected: ///Internal name of currently selected device std::string device_name; diff --git a/src/input_common/sdl_input/sdl_input.cpp b/src/input_common/sdl_input/sdl_input.cpp index 5df4fd10d..298c41011 100644 --- a/src/input_common/sdl_input/sdl_input.cpp +++ b/src/input_common/sdl_input/sdl_input.cpp @@ -18,10 +18,7 @@ SDLController::SDLController() { controller.touch_screen_x = 0; controller.touch_screen_y = 0; - //Immediately shutdown if initialization fails - if(!Init()) { - ShutDown(); - } + activated = Init(); } SDLController::~SDLController() { @@ -43,6 +40,8 @@ bool SDLController::Init() { return false; } + device_name = SDL_JoystickNameForIndex(index); + //If joystick successfully opened, load up keymap from input configuration //TODO - Make it NOT hardcoded joypad_id = KeyMap::NewDeviceId(); @@ -50,6 +49,8 @@ bool SDLController::Init() { //TODO - Make it NOT hardcoded SetDeadZone(8000); + + return true; } void SDLController::DiscoverDevices() {} @@ -59,8 +60,6 @@ void SDLController::ShutDown() { if(jpad != nullptr) { SDL_JoystickClose(jpad); } - - InputCommon::ShutDown(); } void SDLController::Poll() {