Skip to content

Commit

Permalink
Add option to disable SDL joystick support.
Browse files Browse the repository at this point in the history
This also adds some extra sanity checks to avoid crashes when the joystick isn't initialized.
  • Loading branch information
Cacodemon345 authored and alexey-lysiuk committed Jun 4, 2020
1 parent 5151dff commit 9bf0f9b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
5 changes: 5 additions & 0 deletions src/CMakeLists.txt
Expand Up @@ -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 )
Expand Down
9 changes: 6 additions & 3 deletions src/common/platform/posix/sdl/i_joystick.cpp
Expand Up @@ -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()
{
Expand All @@ -316,7 +318,8 @@ void I_GetJoysticks(TArray<IJoystickConfig *> &sticks)
{
sticks.Clear();

JoystickManager->GetDevices(sticks);
if (JoystickManager)
JoystickManager->GetDevices(sticks);
}

void I_GetAxes(float axes[NUM_JOYAXIS])
Expand All @@ -325,15 +328,15 @@ void I_GetAxes(float axes[NUM_JOYAXIS])
{
axes[i] = 0;
}
if (use_joystick)
if (use_joystick && JoystickManager)
{
JoystickManager->AddAxes(axes);
}
}

void I_ProcessJoysticks()
{
if (use_joystick)
if (use_joystick && JoystickManager)
JoystickManager->ProcessInput();
}

Expand Down

0 comments on commit 9bf0f9b

Please sign in to comment.