diff --git a/src/input_common/input_common.cpp b/src/input_common/input_common.cpp index b84dad121..db3480281 100644 --- a/src/input_common/input_common.cpp +++ b/src/input_common/input_common.cpp @@ -64,6 +64,15 @@ void Init(ControllerBackends backend) { CoreTiming::ScheduleEvent(frame_ticks, input_event); } +void ShutDown() { + //Delete the current user input plugin + if(g_user_input != nullptr) + { + delete g_user_input; + g_user_input = nullptr; + } +} + } // namespace diff --git a/src/input_common/input_common.h b/src/input_common/input_common.h index f8ce1cd5f..5126f0b72 100644 --- a/src/input_common/input_common.h +++ b/src/input_common/input_common.h @@ -49,6 +49,9 @@ protected: ///Initialize the user input system void Init(ControllerBackends backend); +///Deactive the user input system +void ShutDown(); + ///InputCommon 'plugin' extern ControllerBase* g_user_input; diff --git a/src/input_common/sdl_input/sdl_input.cpp b/src/input_common/sdl_input/sdl_input.cpp index 3d5663ab5..5df4fd10d 100644 --- a/src/input_common/sdl_input/sdl_input.cpp +++ b/src/input_common/sdl_input/sdl_input.cpp @@ -18,7 +18,10 @@ SDLController::SDLController() { controller.touch_screen_x = 0; controller.touch_screen_y = 0; - Init(); + //Immediately shutdown if initialization fails + if(!Init()) { + ShutDown(); + } } SDLController::~SDLController() { @@ -37,7 +40,6 @@ bool SDLController::Init() { jpad = SDL_JoystickOpen(index); if(jpad == nullptr) { - std::cout<<"What\n"; return false; } @@ -58,8 +60,7 @@ void SDLController::ShutDown() { SDL_JoystickClose(jpad); } - //Delete the current user input plugin - delete g_user_input; + InputCommon::ShutDown(); } void SDLController::Poll() {