Fix SDL2 losing event subsystem

Quiting SDL Video or Joystick subsystem implies quiting the Event subsystem in SDL2.
SDL keeps track of number of init and shutdown calls for each subsystem.
Shuting down video or joystick more or equal to number of times they're inited will lead to event shutdown.

Toggling in and out of fullscreen or running in_restart twice causes SDL event subsystem to shutdown, making input not work.

If the console is closed, IN_GobbleMotionEvents gets stuck in a loop. SDL_PeepEvents returns -1 when there is an error, but we assume non-0 means read more events.

IN_ShutdownJoystick needs to check if joystick subsystem was inited before quitting it, otherwise we may cause SDL event subsystem to shutdown.
This commit is contained in:
Zack Middleton 2013-10-18 16:31:19 -05:00
parent 6831db0563
commit c6a61d212a

View file

@ -297,11 +297,15 @@ IN_GobbleMotionEvents
static void IN_GobbleMotionEvents( void )
{
SDL_Event dummy[ 1 ];
int val = 0;
// Gobble any mouse motion events
SDL_PumpEvents( );
while( SDL_PeepEvents( dummy, 1, SDL_GETEVENT,
SDL_MOUSEMOTION, SDL_MOUSEMOTION ) ) { }
while( ( val = SDL_PeepEvents( dummy, 1, SDL_GETEVENT,
SDL_MOUSEMOTION, SDL_MOUSEMOTION ) ) > 0 ) { }
if ( val < 0 )
Com_Printf( "IN_GobbleMotionEvents failed: %s\n", SDL_GetError( ) );
}
/*
@ -484,6 +488,9 @@ IN_ShutdownJoystick
*/
static void IN_ShutdownJoystick( void )
{
if ( !SDL_WasInit( SDL_INIT_JOYSTICK ) )
return;
if (stick)
{
SDL_JoystickClose(stick);