summaryrefslogtreecommitdiff
path: root/src/sdl/sdl_glimp.c
diff options
context:
space:
mode:
authorTim Angus <tim@ngus.net>2016-04-09 17:57:28 +0100
committerTim Angus <tim@ngus.net>2016-04-09 17:57:28 +0100
commitf45fbef604e05144057dec8d1dbfc5d4f5a2a822 (patch)
tree152d2a428b078f7a89756ea9e156695fc69f1686 /src/sdl/sdl_glimp.c
parent7f9e97d611b4b267d9dd913144cb9632f96c90c2 (diff)
parent87abdd914988724e164ffb16380ad26be8420b84 (diff)
Merge branch 'master' into gpp
Diffstat (limited to 'src/sdl/sdl_glimp.c')
-rw-r--r--src/sdl/sdl_glimp.c42
1 files changed, 33 insertions, 9 deletions
diff --git a/src/sdl/sdl_glimp.c b/src/sdl/sdl_glimp.c
index 51b448a2..fed3fc5b 100644
--- a/src/sdl/sdl_glimp.c
+++ b/src/sdl/sdl_glimp.c
@@ -135,19 +135,32 @@ static void GLimp_DetectAvailableModes(void)
{
int i, j;
char buf[ MAX_STRING_CHARS ] = { 0 };
- SDL_Rect modes[ 128 ];
+ int numSDLModes;
+ SDL_Rect *modes;
int numModes = 0;
- int display = SDL_GetWindowDisplayIndex( SDL_window );
SDL_DisplayMode windowMode;
+ int display = SDL_GetWindowDisplayIndex( SDL_window );
+ if( display < 0 )
+ {
+ ri.Printf( PRINT_WARNING, "Couldn't get window display index, no resolutions detected: %s\n", SDL_GetError() );
+ return;
+ }
+ numSDLModes = SDL_GetNumDisplayModes( display );
- if( SDL_GetWindowDisplayMode( SDL_window, &windowMode ) < 0 )
+ if( SDL_GetWindowDisplayMode( SDL_window, &windowMode ) < 0 || numSDLModes <= 0 )
{
- ri.Printf( PRINT_WARNING, "Couldn't get window display mode, no resolutions detected\n" );
+ ri.Printf( PRINT_WARNING, "Couldn't get window display mode, no resolutions detected: %s\n", SDL_GetError() );
return;
}
- for( i = 0; i < SDL_GetNumDisplayModes( display ); i++ )
+ modes = SDL_calloc( (size_t)numSDLModes, sizeof( SDL_Rect ) );
+ if ( !modes )
+ {
+ ri.Error( ERR_FATAL, "Out of memory" );
+ }
+
+ for( i = 0; i < numSDLModes; i++ )
{
SDL_DisplayMode mode;
@@ -157,6 +170,7 @@ static void GLimp_DetectAvailableModes(void)
if( !mode.w || !mode.h )
{
ri.Printf( PRINT_ALL, "Display supports any resolution\n" );
+ SDL_free( modes );
return;
}
@@ -198,6 +212,7 @@ static void GLimp_DetectAvailableModes(void)
ri.Printf( PRINT_ALL, "Available modes: '%s'\n", buf );
ri.Cvar_Set( "r_availableModes", buf );
}
+ SDL_free( modes );
}
#define R_FAILSAFE_WIDTH 640
@@ -243,9 +258,15 @@ static int GLimp_SetMode( qboolean failSafe, qboolean fullscreen, qboolean nobor
// If a window exists, note its display index
if( SDL_window != NULL )
+ {
display = SDL_GetWindowDisplayIndex( SDL_window );
+ if( display < 0 )
+ {
+ ri.Printf( PRINT_DEVELOPER, "SDL_GetWindowDisplayIndex() failed: %s\n", SDL_GetError() );
+ }
+ }
- if( SDL_GetDesktopDisplayMode( display, &desktopMode ) == 0 )
+ if( display >= 0 && SDL_GetDesktopDisplayMode( display, &desktopMode ) == 0 )
{
glConfig.displayAspect = (float)desktopMode.w / (float)desktopMode.h;
@@ -445,7 +466,7 @@ static int GLimp_SetMode( qboolean failSafe, qboolean fullscreen, qboolean nobor
#endif
if( ( SDL_window = SDL_CreateWindow( CLIENT_WINDOW_TITLE, x, y,
- glConfig.vidWidth, glConfig.vidHeight, flags ) ) == 0 )
+ glConfig.vidWidth, glConfig.vidHeight, flags ) ) == NULL )
{
ri.Printf( PRINT_DEVELOPER, "SDL_CreateWindow failed: %s\n", SDL_GetError( ) );
continue;
@@ -486,7 +507,10 @@ static int GLimp_SetMode( qboolean failSafe, qboolean fullscreen, qboolean nobor
qglClear( GL_COLOR_BUFFER_BIT );
SDL_GL_SwapWindow( SDL_window );
- SDL_GL_SetSwapInterval( r_swapInterval->integer );
+ if( SDL_GL_SetSwapInterval( r_swapInterval->integer ) == -1 )
+ {
+ ri.Printf( PRINT_DEVELOPER, "SDL_GL_SetSwapInterval failed: %s\n", SDL_GetError( ) );
+ }
glConfig.colorBits = testColorBits;
glConfig.depthBits = testDepthBits;
@@ -526,7 +550,7 @@ static qboolean GLimp_StartDriverAndSetMode( qboolean failSafe, qboolean fullscr
{
const char *driverName;
- if (SDL_Init(SDL_INIT_VIDEO) == -1)
+ if (SDL_Init(SDL_INIT_VIDEO) != 0)
{
ri.Printf( PRINT_ALL, "SDL_Init( SDL_INIT_VIDEO ) FAILED (%s)\n", SDL_GetError());
return qfalse;