From 490d0b226e6a08433a12b356cc1460e0a50019b1 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Wed, 1 Oct 2014 09:35:49 +0100 Subject: Don't crash if more than 128 modes are available --- src/sdl/sdl_glimp.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'src/sdl') diff --git a/src/sdl/sdl_glimp.c b/src/sdl/sdl_glimp.c index 51b448a2..1f45551f 100644 --- a/src/sdl/sdl_glimp.c +++ b/src/sdl/sdl_glimp.c @@ -135,7 +135,8 @@ static void GLimp_DetectAvailableModes(void) { int i, j; char buf[ MAX_STRING_CHARS ] = { 0 }; - SDL_Rect modes[ 128 ]; + size_t numSDLModes; + SDL_Rect *modes; int numModes = 0; int display = SDL_GetWindowDisplayIndex( SDL_window ); @@ -147,7 +148,14 @@ static void GLimp_DetectAvailableModes(void) return; } - for( i = 0; i < SDL_GetNumDisplayModes( display ); i++ ) + numSDLModes = SDL_GetNumDisplayModes( display ); + modes = SDL_calloc( numSDLModes, sizeof( SDL_Rect )); + if ( !modes ) + { + ri.Error( ERR_FATAL, "Out of memory\n" ); + } + + for( i = 0; i < numSDLModes; i++ ) { SDL_DisplayMode mode; @@ -157,6 +165,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 +207,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 -- cgit From 14964e061958f37aff3e4a68f22523df91bdc373 Mon Sep 17 00:00:00 2001 From: Zack Middleton Date: Fri, 12 Jun 2015 12:59:25 -0500 Subject: Remove erroneous new line from error message --- src/sdl/sdl_glimp.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/sdl') diff --git a/src/sdl/sdl_glimp.c b/src/sdl/sdl_glimp.c index 1f45551f..ffda45a0 100644 --- a/src/sdl/sdl_glimp.c +++ b/src/sdl/sdl_glimp.c @@ -149,10 +149,10 @@ static void GLimp_DetectAvailableModes(void) } numSDLModes = SDL_GetNumDisplayModes( display ); - modes = SDL_calloc( numSDLModes, sizeof( SDL_Rect )); + modes = SDL_calloc( numSDLModes, sizeof( SDL_Rect ) ); if ( !modes ) { - ri.Error( ERR_FATAL, "Out of memory\n" ); + ri.Error( ERR_FATAL, "Out of memory" ); } for( i = 0; i < numSDLModes; i++ ) -- cgit From cd73fc454e392d04156582984bccb4289307b2f3 Mon Sep 17 00:00:00 2001 From: Tim Angus Date: Sun, 28 Jun 2015 18:01:03 +0100 Subject: Check SDL_GetNumDisplayModes return value for errors --- src/sdl/sdl_glimp.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/sdl') diff --git a/src/sdl/sdl_glimp.c b/src/sdl/sdl_glimp.c index ffda45a0..2141c2bb 100644 --- a/src/sdl/sdl_glimp.c +++ b/src/sdl/sdl_glimp.c @@ -135,21 +135,21 @@ static void GLimp_DetectAvailableModes(void) { int i, j; char buf[ MAX_STRING_CHARS ] = { 0 }; - size_t numSDLModes; + int numSDLModes; SDL_Rect *modes; int numModes = 0; int display = SDL_GetWindowDisplayIndex( SDL_window ); + numSDLModes = SDL_GetNumDisplayModes( display ); SDL_DisplayMode windowMode; - 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" ); return; } - numSDLModes = SDL_GetNumDisplayModes( display ); - modes = SDL_calloc( numSDLModes, sizeof( SDL_Rect ) ); + modes = SDL_calloc( (size_t)numSDLModes, sizeof( SDL_Rect ) ); if ( !modes ) { ri.Error( ERR_FATAL, "Out of memory" ); -- cgit From db361cbe859974162cf7c2d467b3209c692824f0 Mon Sep 17 00:00:00 2001 From: Zack Middleton Date: Sun, 28 Jun 2015 16:29:10 -0500 Subject: Fix variable declaration for C89 compilers --- src/sdl/sdl_glimp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/sdl') diff --git a/src/sdl/sdl_glimp.c b/src/sdl/sdl_glimp.c index 2141c2bb..b41da64c 100644 --- a/src/sdl/sdl_glimp.c +++ b/src/sdl/sdl_glimp.c @@ -139,9 +139,9 @@ static void GLimp_DetectAvailableModes(void) SDL_Rect *modes; int numModes = 0; + SDL_DisplayMode windowMode; int display = SDL_GetWindowDisplayIndex( SDL_window ); numSDLModes = SDL_GetNumDisplayModes( display ); - SDL_DisplayMode windowMode; if( SDL_GetWindowDisplayMode( SDL_window, &windowMode ) < 0 || numSDLModes <= 0 ) { -- cgit From 95cc01fb25e20822fe9b091702789111cc5d1b8b Mon Sep 17 00:00:00 2001 From: Pan7 Date: Fri, 24 Jul 2015 22:56:00 +0200 Subject: SDL_Init zero check --- src/sdl/sdl_glimp.c | 2 +- src/sdl/sdl_input.c | 2 +- src/sdl/sdl_snd.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'src/sdl') diff --git a/src/sdl/sdl_glimp.c b/src/sdl/sdl_glimp.c index b41da64c..9f86dd9e 100644 --- a/src/sdl/sdl_glimp.c +++ b/src/sdl/sdl_glimp.c @@ -536,7 +536,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; diff --git a/src/sdl/sdl_input.c b/src/sdl/sdl_input.c index 2b466744..fbe90d08 100644 --- a/src/sdl/sdl_input.c +++ b/src/sdl/sdl_input.c @@ -486,7 +486,7 @@ static void IN_InitJoystick( void ) if (!SDL_WasInit(SDL_INIT_JOYSTICK)) { Com_DPrintf("Calling SDL_Init(SDL_INIT_JOYSTICK)...\n"); - if (SDL_Init(SDL_INIT_JOYSTICK) == -1) + if (SDL_Init(SDL_INIT_JOYSTICK) != 0) { Com_DPrintf("SDL_Init(SDL_INIT_JOYSTICK) failed: %s\n", SDL_GetError()); return; diff --git a/src/sdl/sdl_snd.c b/src/sdl/sdl_snd.c index a087c486..9420f0ba 100644 --- a/src/sdl/sdl_snd.c +++ b/src/sdl/sdl_snd.c @@ -157,7 +157,7 @@ qboolean SNDDMA_Init(void) if (!SDL_WasInit(SDL_INIT_AUDIO)) { - if (SDL_Init(SDL_INIT_AUDIO) == -1) + if (SDL_Init(SDL_INIT_AUDIO) != 0) { Com_Printf( "FAILED (%s)\n", SDL_GetError( ) ); return qfalse; -- cgit From f3d9ff7b490b6f3ce355e3f4441f7758340a096b Mon Sep 17 00:00:00 2001 From: Pan7 Date: Sun, 26 Jul 2015 03:21:45 +0200 Subject: SDL_FALSE/TRUE for SDL_SetWindowGrab --- src/sdl/sdl_input.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/sdl') diff --git a/src/sdl/sdl_input.c b/src/sdl/sdl_input.c index fbe90d08..700834c2 100644 --- a/src/sdl/sdl_input.c +++ b/src/sdl/sdl_input.c @@ -366,7 +366,7 @@ static void IN_ActivateMouse( void ) if( !mouseActive ) { SDL_SetRelativeMouseMode( SDL_TRUE ); - SDL_SetWindowGrab( SDL_window, 1 ); + SDL_SetWindowGrab( SDL_window, SDL_TRUE ); IN_GobbleMotionEvents( ); } @@ -377,9 +377,9 @@ static void IN_ActivateMouse( void ) if( in_nograb->modified || !mouseActive ) { if( in_nograb->integer ) - SDL_SetWindowGrab( SDL_window, 0 ); + SDL_SetWindowGrab( SDL_window, SDL_FALSE ); else - SDL_SetWindowGrab( SDL_window, 1 ); + SDL_SetWindowGrab( SDL_window, SDL_TRUE ); in_nograb->modified = qfalse; } @@ -416,7 +416,7 @@ static void IN_DeactivateMouse( void ) { IN_GobbleMotionEvents( ); - SDL_SetWindowGrab( SDL_window, 0 ); + SDL_SetWindowGrab( SDL_window, SDL_FALSE ); SDL_SetRelativeMouseMode( SDL_FALSE ); // Don't warp the mouse unless the cursor is within the window -- cgit From d3e4081ba8961e9d0eec4927b4a83b084dc02723 Mon Sep 17 00:00:00 2001 From: Pan7 Date: Sun, 26 Jul 2015 04:31:27 +0200 Subject: SDL_SetWindowGammaRamp check --- src/sdl/sdl_gamma.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/sdl') diff --git a/src/sdl/sdl_gamma.c b/src/sdl/sdl_gamma.c index 0029db18..2f807055 100644 --- a/src/sdl/sdl_gamma.c +++ b/src/sdl/sdl_gamma.c @@ -89,6 +89,9 @@ void GLimp_SetGamma( unsigned char red[256], unsigned char green[256], unsigned } } - SDL_SetWindowGammaRamp(SDL_window, table[0], table[1], table[2]); + if (SDL_SetWindowGammaRamp(SDL_window, table[0], table[1], table[2]) < 0) + { + ri.Printf( PRINT_DEVELOPER, "SDL_SetWindowGammaRamp() failed.\n" ); + } } -- cgit From 6a1b563be8d358a7d4af5b43307ace4c5f2c6a99 Mon Sep 17 00:00:00 2001 From: Pan7 Date: Sun, 26 Jul 2015 13:03:47 +0200 Subject: SDL_GetWindowDisplayIndex check --- src/sdl/sdl_glimp.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/sdl') diff --git a/src/sdl/sdl_glimp.c b/src/sdl/sdl_glimp.c index 9f86dd9e..e979ba1f 100644 --- a/src/sdl/sdl_glimp.c +++ b/src/sdl/sdl_glimp.c @@ -141,6 +141,11 @@ static void GLimp_DetectAvailableModes(void) 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\n" ); + return; + } numSDLModes = SDL_GetNumDisplayModes( display ); if( SDL_GetWindowDisplayMode( SDL_window, &windowMode ) < 0 || numSDLModes <= 0 ) -- cgit From 969f68f3c17199073643a138f12f9b6dae0717bb Mon Sep 17 00:00:00 2001 From: Pan7 Date: Sun, 26 Jul 2015 13:54:29 +0200 Subject: SDL_CreateWindow NULL check --- src/sdl/sdl_glimp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/sdl') diff --git a/src/sdl/sdl_glimp.c b/src/sdl/sdl_glimp.c index e979ba1f..d7536794 100644 --- a/src/sdl/sdl_glimp.c +++ b/src/sdl/sdl_glimp.c @@ -460,7 +460,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; -- cgit From fc530362b74857609f1a73bbe2339f0609b04a8f Mon Sep 17 00:00:00 2001 From: Pan7 Date: Sun, 26 Jul 2015 15:41:41 +0200 Subject: Added SDL_GetError() --- src/sdl/sdl_glimp.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/sdl') diff --git a/src/sdl/sdl_glimp.c b/src/sdl/sdl_glimp.c index d7536794..e4c816c0 100644 --- a/src/sdl/sdl_glimp.c +++ b/src/sdl/sdl_glimp.c @@ -143,14 +143,14 @@ static void GLimp_DetectAvailableModes(void) int display = SDL_GetWindowDisplayIndex( SDL_window ); if( display < 0 ) { - ri.Printf( PRINT_WARNING, "Couldn't get window display index, no resolutions detected\n" ); + 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 || 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; } -- cgit From 12c86c4d96fb34625ac439458055a919956e3f7c Mon Sep 17 00:00:00 2001 From: Pan7 Date: Sun, 26 Jul 2015 15:45:21 +0200 Subject: Added SDL_GetError() --- src/sdl/sdl_gamma.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/sdl') diff --git a/src/sdl/sdl_gamma.c b/src/sdl/sdl_gamma.c index 2f807055..7e030683 100644 --- a/src/sdl/sdl_gamma.c +++ b/src/sdl/sdl_gamma.c @@ -91,7 +91,7 @@ void GLimp_SetGamma( unsigned char red[256], unsigned char green[256], unsigned if (SDL_SetWindowGammaRamp(SDL_window, table[0], table[1], table[2]) < 0) { - ri.Printf( PRINT_DEVELOPER, "SDL_SetWindowGammaRamp() failed.\n" ); + ri.Printf( PRINT_DEVELOPER, "SDL_SetWindowGammaRamp() failed: %s\n", SDL_GetError() ); } } -- cgit From 22b5d7b96190ada24158a9ba41fee893f1a5cb46 Mon Sep 17 00:00:00 2001 From: Pan7 Date: Sun, 26 Jul 2015 19:46:07 +0200 Subject: SDL_GetWindowDisplayIndex() check2 --- src/sdl/sdl_glimp.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'src/sdl') diff --git a/src/sdl/sdl_glimp.c b/src/sdl/sdl_glimp.c index e4c816c0..efe712fd 100644 --- a/src/sdl/sdl_glimp.c +++ b/src/sdl/sdl_glimp.c @@ -258,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; -- cgit From 483b91152ca6f2449bf632214f32a8ebbce3fc7d Mon Sep 17 00:00:00 2001 From: Pan7 Date: Sun, 26 Jul 2015 20:23:48 +0200 Subject: SDL_GL_SetSwapInterval() check --- src/sdl/sdl_glimp.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/sdl') diff --git a/src/sdl/sdl_glimp.c b/src/sdl/sdl_glimp.c index efe712fd..fed3fc5b 100644 --- a/src/sdl/sdl_glimp.c +++ b/src/sdl/sdl_glimp.c @@ -507,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; -- cgit