From 2f43d8b9bfa4745997090e482a3ab31675da317d Mon Sep 17 00:00:00 2001 From: Zack Middleton Date: Fri, 18 Oct 2013 16:31:19 -0500 Subject: 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. --- src/sdl/sdl_input.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'src/sdl') diff --git a/src/sdl/sdl_input.c b/src/sdl/sdl_input.c index f241f225..affe2d41 100644 --- a/src/sdl/sdl_input.c +++ b/src/sdl/sdl_input.c @@ -298,11 +298,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( ) ); } /* @@ -533,6 +537,9 @@ IN_ShutdownJoystick */ static void IN_ShutdownJoystick( void ) { + if ( !SDL_WasInit( SDL_INIT_JOYSTICK ) ) + return; + if (stick) { SDL_JoystickClose(stick); -- cgit