Skip to content

Commit 191149b

Browse files
committed
Fix infinite vid_restart loop from SDL resize events on macOS
On macOS, the SDL2 Cocoa backend fires SDL_WINDOWEVENT_RESIZED during fullscreen window creation as the window goes through a size negotiation with the window server. Since vid_restart destroys and recreates the SDL window, each restart triggers a resize event with the same dimensions, which sets vidRestartTime, which fires another vid_restart one second later, creating an infinite loop. This does not occur on Linux or Windows where the X11/Win32 backends do not emit resize events during fullscreen window creation. Skip the vidRestartTime when the reported dimensions match what r_customwidth and r_customheight already hold.
1 parent e8f5ed1 commit 191149b

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)