diff options
author | thilo <thilo@edf5b092-35ff-0310-97b2-ce42778d08ea> | 2008-04-06 02:13:43 +0000 |
---|---|---|
committer | thilo <thilo@edf5b092-35ff-0310-97b2-ce42778d08ea> | 2008-04-06 02:13:43 +0000 |
commit | e32d29a6db0b593e4e61188ed3ffc1449605ebc9 (patch) | |
tree | 9661a93c6078637ad615c8a8a36e4c8d041d389a | |
parent | 55634342dda65d9f885024e88573bb7db8b26799 (diff) | |
download | ioquake3-aero-e32d29a6db0b593e4e61188ed3ffc1449605ebc9.tar.gz ioquake3-aero-e32d29a6db0b593e4e61188ed3ffc1449605ebc9.zip |
Make sure that one broken shader file cannot crash the game / make the other shaders unusable.
git-svn-id: svn://svn.icculus.org/quake3/trunk@1295 edf5b092-35ff-0310-97b2-ce42778d08ea
-rw-r--r-- | code/qcommon/q_shared.c | 2 | ||||
-rw-r--r-- | code/renderer/tr_shader.c | 50 |
2 files changed, 42 insertions, 10 deletions
diff --git a/code/qcommon/q_shared.c b/code/qcommon/q_shared.c index 18b71d3..6fa6b76 100644 --- a/code/qcommon/q_shared.c +++ b/code/qcommon/q_shared.c @@ -599,7 +599,7 @@ void SkipBracedSection (char **program) { depth = 0; do { token = COM_ParseExt( program, qtrue ); - if( token[1] == 0 ) { + if( *program && token[1] == 0 ) { if( token[0] == '{' ) { depth++; } diff --git a/code/renderer/tr_shader.c b/code/renderer/tr_shader.c index 275e32d..830a410 100644 --- a/code/renderer/tr_shader.c +++ b/code/renderer/tr_shader.c @@ -2868,7 +2868,7 @@ static void ScanAndLoadShaderFiles( void ) char *oldp, *token, *hashMem; int shaderTextHashTableSizes[MAX_SHADERTEXT_HASH], hash, size; - long sum = 0; + long sum = 0, summand; // scan for shader files shaderFiles = ri.FS_ListFiles( "scripts", ".shader", &numShaderFiles ); @@ -2889,10 +2889,38 @@ static void ScanAndLoadShaderFiles( void ) Com_sprintf( filename, sizeof( filename ), "scripts/%s", shaderFiles[i] ); ri.Printf( PRINT_DEVELOPER, "...loading '%s'\n", filename ); - sum += ri.FS_ReadFile( filename, (void **)&buffers[i] ); - if ( !buffers[i] ) { + summand = ri.FS_ReadFile( filename, (void **)&buffers[i] ); + + if ( !buffers[i] ) ri.Error( ERR_DROP, "Couldn't load %s", filename ); + + // Do a simple check on the shader structure in that file to make sure one bad shader file cannot fuck up all other shaders. + p = buffers[i]; + while(1) + { + token = COM_ParseExt(&p, qtrue); + + if(!*token) + break; + + oldp = p; + + token = COM_ParseExt(&p, qtrue); + if(*token != '{') + { + ri.Printf(PRINT_WARNING, "WARNING: Bad shader file %s has incorrect syntax.\n", filename); + ri.FS_FreeFile(buffers[i]); + buffers[i] = NULL; + break; + } + + SkipBracedSection(&oldp); + p = oldp; } + + + if (buffers[i]) + sum += summand; } // build single large buffer @@ -2900,12 +2928,16 @@ static void ScanAndLoadShaderFiles( void ) s_shaderText[ 0 ] = '\0'; // free in reverse order, so the temp files are all dumped - for ( i = numShaderFiles - 1; i >= 0 ; i-- ) { - p = &s_shaderText[strlen(s_shaderText)]; - strcat( s_shaderText, buffers[i] ); - ri.FS_FreeFile( buffers[i] ); - COM_Compress(p); - strcat( s_shaderText, "\n" ); + for ( i = numShaderFiles - 1; i >= 0 ; i-- ) + { + if(buffers[i]) + { + p = &s_shaderText[strlen(s_shaderText)]; + strcat( s_shaderText, buffers[i] ); + ri.FS_FreeFile( buffers[i] ); + COM_Compress(p); + strcat( s_shaderText, "\n" ); + } } // free up memory |