mirror of
https://github.com/ioquake/ioq3.git
synced 2024-11-10 07:11:46 +00:00
Merge pull request #105 from smcv/sdl-modes
Don't crash if more than 128 modes are available
This commit is contained in:
commit
77ad75887f
1 changed files with 12 additions and 2 deletions
|
@ -130,7 +130,8 @@ static void GLimp_DetectAvailableModes(void)
|
||||||
{
|
{
|
||||||
int i, j;
|
int i, j;
|
||||||
char buf[ MAX_STRING_CHARS ] = { 0 };
|
char buf[ MAX_STRING_CHARS ] = { 0 };
|
||||||
SDL_Rect modes[ 128 ];
|
size_t numSDLModes;
|
||||||
|
SDL_Rect *modes;
|
||||||
int numModes = 0;
|
int numModes = 0;
|
||||||
|
|
||||||
int display = SDL_GetWindowDisplayIndex( SDL_window );
|
int display = SDL_GetWindowDisplayIndex( SDL_window );
|
||||||
|
@ -142,7 +143,14 @@ static void GLimp_DetectAvailableModes(void)
|
||||||
return;
|
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;
|
SDL_DisplayMode mode;
|
||||||
|
|
||||||
|
@ -152,6 +160,7 @@ static void GLimp_DetectAvailableModes(void)
|
||||||
if( !mode.w || !mode.h )
|
if( !mode.w || !mode.h )
|
||||||
{
|
{
|
||||||
ri.Printf( PRINT_ALL, "Display supports any resolution\n" );
|
ri.Printf( PRINT_ALL, "Display supports any resolution\n" );
|
||||||
|
SDL_free( modes );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -193,6 +202,7 @@ static void GLimp_DetectAvailableModes(void)
|
||||||
ri.Printf( PRINT_ALL, "Available modes: '%s'\n", buf );
|
ri.Printf( PRINT_ALL, "Available modes: '%s'\n", buf );
|
||||||
ri.Cvar_Set( "r_availableModes", buf );
|
ri.Cvar_Set( "r_availableModes", buf );
|
||||||
}
|
}
|
||||||
|
SDL_free( modes );
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
Loading…
Reference in a new issue