From 1703988f00782a9315586c4393cddd6a3061788b Mon Sep 17 00:00:00 2001 From: Daniel Stuart Baxter Date: Sat, 30 May 2015 15:21:27 -0500 Subject: [PATCH] Improve shutdown again --- src/input_common/input_common.cpp | 13 ++++++++----- src/input_common/input_common.h | 2 ++ src/input_common/sdl_input/sdl_input.cpp | 11 +++++------ 3 files changed, 15 insertions(+), 11 deletions(-) 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() {