Skip to content

Commit 905059d

Browse files
authored
Merge pull request #106 from jackharrhy/fix/sdl-resize-loop
Fix infinite vid_restart loop from SDL resize events on macOS
2 parents e8f5ed1 + 191149b commit 905059d

1 file changed

Lines changed: 20 additions & 11 deletions

File tree

code/sdl/sdl_input.c

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1185,17 +1185,26 @@ static void IN_ProcessEvents( void )
11851185
{
11861186
case SDL_WINDOWEVENT_RESIZED:
11871187
{
1188-
char width[32], height[32];
1189-
Com_sprintf( width, sizeof( width ), "%d", e.window.data1 );
1190-
Com_sprintf( height, sizeof( height ), "%d", e.window.data2 );
1191-
Cvar_Set( "r_customwidth", width );
1192-
Cvar_Set( "r_customheight", height );
1193-
Cvar_Set( "r_mode", "-1" );
1194-
1195-
// Wait until user stops dragging for 1 second, so
1196-
// we aren't constantly recreating the GL context while
1197-
// he tries to drag...
1198-
vidRestartTime = Sys_Milliseconds( ) + 1000;
1188+
int newWidth = e.window.data1;
1189+
int newHeight = e.window.data2;
1190+
1191+
// Ignore spurious resize events fired when the window is
1192+
// recreated at the same size (e.g. after vid_restart on macOS).
1193+
if( newWidth != Cvar_VariableIntegerValue( "r_customwidth" ) ||
1194+
newHeight != Cvar_VariableIntegerValue( "r_customheight" ) )
1195+
{
1196+
char width[32], height[32];
1197+
Com_sprintf( width, sizeof( width ), "%d", newWidth );
1198+
Com_sprintf( height, sizeof( height ), "%d", newHeight );
1199+
Cvar_Set( "r_customwidth", width );
1200+
Cvar_Set( "r_customheight", height );
1201+
Cvar_Set( "r_mode", "-1" );
1202+
1203+
// Wait until user stops dragging for 1 second, so
1204+
// we aren't constantly recreating the GL context while
1205+
// he tries to drag...
1206+
vidRestartTime = Sys_Milliseconds( ) + 1000;
1207+
}
11991208
}
12001209
break;
12011210

0 commit comments

Comments
 (0)