Skip to content

Commit

Permalink
Fix joystick w/o controller mapping not working with SDL update.
Browse files Browse the repository at this point in the history
  • Loading branch information
SmileTheory committed Aug 17, 2016
1 parent fb65e12 commit c5c01e7
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion code/sdl/sdl_input.c
Expand Up @@ -439,6 +439,21 @@ static void IN_InitJoystick( void )
gamepad = NULL;
memset(&stick_state, '\0', sizeof (stick_state));

// SDL 2.0.4 requires SDL_INIT_JOYSTICK to be initialized separately from
// SDL_INIT_GAMECONTROLLER for SDL_JoystickOpen() to work correctly,
// despite https://wiki.libsdl.org/SDL_Init (retrieved 2016-08-16)
// indicating SDL_INIT_JOYSTICK should be initialized automatically.
if (!SDL_WasInit(SDL_INIT_JOYSTICK))
{
Com_DPrintf("Calling SDL_Init(SDL_INIT_JOYSTICK)...\n");
if (SDL_Init(SDL_INIT_JOYSTICK) != 0)
{
Com_DPrintf("SDL_Init(SDL_INIT_JOYSTICK) failed: %s\n", SDL_GetError());
return;
}
Com_DPrintf("SDL_Init(SDL_INIT_JOYSTICK) passed.\n");
}

if (!SDL_WasInit(SDL_INIT_GAMECONTROLLER))
{
Com_DPrintf("Calling SDL_Init(SDL_INIT_GAMECONTROLLER)...\n");
Expand Down Expand Up @@ -477,7 +492,7 @@ static void IN_InitJoystick( void )
stick = SDL_JoystickOpen( in_joystickNo->integer );

if (stick == NULL) {
Com_DPrintf( "No joystick opened.\n" );
Com_DPrintf( "No joystick opened: %s\n", SDL_GetError() );
return;
}

Expand Down Expand Up @@ -507,6 +522,9 @@ static void IN_ShutdownJoystick( void )
if ( !SDL_WasInit( SDL_INIT_GAMECONTROLLER ) )
return;

if ( !SDL_WasInit( SDL_INIT_JOYSTICK ) )
return;

if (gamepad)
{
SDL_GameControllerClose(gamepad);
Expand All @@ -520,6 +538,7 @@ static void IN_ShutdownJoystick( void )
}

SDL_QuitSubSystem(SDL_INIT_GAMECONTROLLER);
SDL_QuitSubSystem(SDL_INIT_JOYSTICK);
}


Expand Down

0 comments on commit c5c01e7

Please sign in to comment.