Skip to content

Commit b7589ab

Browse files
committed
Fix inconsistent r_displayIndex logic
Fix duplicated and inconsistent logic for confining r_displayIndex to the available range of values (my fault with the amendments to the SDL3 commit). Also don't modify the value of r_displayIndex.
1 parent d477286 commit b7589ab

2 files changed

Lines changed: 7 additions & 23 deletions

File tree

src/engine/renderer/tr_public.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ struct GLConfig
6262

6363
textureCompression_t textureCompression;
6464

65-
int displayIndex;
65+
uint32_t sdlDisplayID;
6666

6767
bool smpActive; // dual processor
6868

src/engine/sys/sdl_glimp.cpp

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -848,23 +848,8 @@ static bool GLimp_CreateWindow( bool fullscreen, bool bordered, const glConfigur
848848
}
849849
}
850850

851-
int numDisplays;
852-
SDL_DisplayID *displayIDs = SDL_GetDisplays( &numDisplays );
853-
854-
if ( !displayIDs )
855-
{
856-
Sys::Error( "SDL_GetDisplays failed: %s", SDL_GetError() );
857-
}
858-
859-
SDL_DisplayID displayID =
860-
r_displayIndex->integer < numDisplays || r_displayIndex->integer > numDisplays
861-
? displayIDs[ r_displayIndex->integer ]
862-
: 0; // 0 implies primary display
863-
864-
SDL_free( displayIDs );
865-
866-
int x = SDL_WINDOWPOS_CENTERED_DISPLAY( displayID );
867-
int y = SDL_WINDOWPOS_CENTERED_DISPLAY( displayID );
851+
int x = SDL_WINDOWPOS_CENTERED_DISPLAY( glConfig.sdlDisplayID );
852+
int y = SDL_WINDOWPOS_CENTERED_DISPLAY( glConfig.sdlDisplayID );
868853

869854
windowProperties = SDL_CreateProperties();
870855
if ( !windowProperties )
@@ -1052,11 +1037,13 @@ static rserr_t GLimp_SetModeAndResolution( const int mode )
10521037
Sys::Error( "SDL_GetDisplays returned 0 displays" );
10531038
}
10541039

1055-
SDL_DisplayID displayID = displayIDs[ Math::Clamp( r_displayIndex->integer, 0, numDisplays - 1 ) ];
1040+
glConfig.sdlDisplayID = r_displayIndex->integer >= 0 && r_displayIndex->integer < numDisplays
1041+
? displayIDs[ r_displayIndex->integer ]
1042+
: 0; // 0 indicates primary display
10561043

10571044
SDL_free( displayIDs );
10581045

1059-
const SDL_DisplayMode *desktopMode = SDL_GetDesktopDisplayMode( displayID );
1046+
const SDL_DisplayMode *desktopMode = SDL_GetDesktopDisplayMode( glConfig.sdlDisplayID );
10601047

10611048
if ( desktopMode )
10621049
{
@@ -1803,9 +1790,6 @@ static rserr_t GLimp_StartDriverAndSetMode( int mode, bool fullscreen, bool bord
18031790
logger.Notice( "Using OpenGL ABI \"%s\"", DAEMON_OPENGL_ABI_STRING );
18041791
#endif
18051792

1806-
AssertCvarRange( r_displayIndex, 0, numDisplays - 1, true );
1807-
glConfig.displayIndex = r_displayIndex->integer;
1808-
18091793
rserr_t err = GLimp_SetMode(mode, fullscreen, bordered);
18101794

18111795
const char* glRequirements =

0 commit comments

Comments
 (0)