From 9bf0f9bbfcac47476d3b18f868852e6250a17934 Mon Sep 17 00:00:00 2001 From: Cacodemon345 Date: Thu, 4 Jun 2020 15:48:59 +0600 Subject: [PATCH] Add option to disable SDL joystick support. This also adds some extra sanity checks to avoid crashes when the joystick isn't initialized. --- src/CMakeLists.txt | 5 +++++ src/common/platform/posix/sdl/i_joystick.cpp | 9 ++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 661214bf16..244ef6329c 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -159,6 +159,11 @@ else() endif() endif() + option( NO_SDL_JOYSTICK "Disable SDL joystick support (Not applicable to Windows)" OFF ) + if ( NO_SDL_JOYSTICK ) + add_definitions( -DNO_SDL_JOYSTICK=1 ) + endif ( NO_SDL_JOYSTICK ) + if( NO_GTK ) add_definitions( -DNO_GTK ) elseif( DYN_GTK ) diff --git a/src/common/platform/posix/sdl/i_joystick.cpp b/src/common/platform/posix/sdl/i_joystick.cpp index 9d5297ba0f..fe4b25eb64 100644 --- a/src/common/platform/posix/sdl/i_joystick.cpp +++ b/src/common/platform/posix/sdl/i_joystick.cpp @@ -300,8 +300,10 @@ static SDLInputJoystickManager *JoystickManager; void I_StartupJoysticks() { +#ifndef NO_SDL_JOYSTICK if(SDL_InitSubSystem(SDL_INIT_JOYSTICK) >= 0) JoystickManager = new SDLInputJoystickManager(); +#endif } void I_ShutdownInput() { @@ -316,7 +318,8 @@ void I_GetJoysticks(TArray &sticks) { sticks.Clear(); - JoystickManager->GetDevices(sticks); + if (JoystickManager) + JoystickManager->GetDevices(sticks); } void I_GetAxes(float axes[NUM_JOYAXIS]) @@ -325,7 +328,7 @@ void I_GetAxes(float axes[NUM_JOYAXIS]) { axes[i] = 0; } - if (use_joystick) + if (use_joystick && JoystickManager) { JoystickManager->AddAxes(axes); } @@ -333,7 +336,7 @@ void I_GetAxes(float axes[NUM_JOYAXIS]) void I_ProcessJoysticks() { - if (use_joystick) + if (use_joystick && JoystickManager) JoystickManager->ProcessInput(); }