From 817abdd579b2918d55141ac8efc9f8c4ef720634 Mon Sep 17 00:00:00 2001 From: Ryan Houdek Date: Mon, 19 Jan 2015 16:05:21 -0600 Subject: [PATCH] Remove an assumption in SDL. We can compile with haptic support, and then not initialize due to haptics not being available. So if we are compiling with haptics, test initializing with haptics and if that fails attempt to initialize without haptics before bailing out. --- .../ControllerInterface/SDL/SDL.cpp | 36 ++++++++++++------- .../InputCommon/ControllerInterface/SDL/SDL.h | 3 -- 2 files changed, 23 insertions(+), 16 deletions(-) diff --git a/Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp b/Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp index a1fd428a0d..2525e273b8 100644 --- a/Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp +++ b/Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp @@ -38,21 +38,31 @@ void Init( std::vector& devices ) // multiple joysticks with the same name shall get unique ids starting at 0 std::map name_counts; - if (SDL_Init( SDL_INIT_FLAGS ) >= 0) +#ifdef USE_SDL_HAPTIC + if (SDL_Init(SDL_INIT_JOYSTICK | SDL_INIT_HAPTIC) >= 0) { - // joysticks - for (int i = 0; i < SDL_NumJoysticks(); ++i) + // Correctly initialized + } + else +#endif + if (SDL_Init(SDL_INIT_JOYSTICK) < 0) + { + // Failed to initialize + return; + } + + // joysticks + for (int i = 0; i < SDL_NumJoysticks(); ++i) + { + SDL_Joystick* dev = SDL_JoystickOpen(i); + if (dev) { - SDL_Joystick* dev = SDL_JoystickOpen(i); - if (dev) - { - Joystick* js = new Joystick(dev, i, name_counts[GetJoystickName(i)]++); - // only add if it has some inputs/outputs - if (js->Inputs().size() || js->Outputs().size()) - devices.push_back( js ); - else - delete js; - } + Joystick* js = new Joystick(dev, i, name_counts[GetJoystickName(i)]++); + // only add if it has some inputs/outputs + if (js->Inputs().size() || js->Outputs().size()) + devices.push_back( js ); + else + delete js; } } } diff --git a/Source/Core/InputCommon/ControllerInterface/SDL/SDL.h b/Source/Core/InputCommon/ControllerInterface/SDL/SDL.h index 2bf695c698..7d722a2d80 100644 --- a/Source/Core/InputCommon/ControllerInterface/SDL/SDL.h +++ b/Source/Core/InputCommon/ControllerInterface/SDL/SDL.h @@ -17,9 +17,6 @@ #ifdef USE_SDL_HAPTIC #include - #define SDL_INIT_FLAGS SDL_INIT_JOYSTICK | SDL_INIT_HAPTIC -#else - #define SDL_INIT_FLAGS SDL_INIT_JOYSTICK #endif namespace ciface