Index: tr_shader.c =================================================================== --- tr_shader.c (revision 1803) +++ tr_shader.c (working copy) @@ -2866,6 +2866,14 @@ ri.Printf (PRINT_ALL, "------------------\n"); } +static char *stradd( char *dst, const char *src ) +{ + char c; + while ( (c = *src++) != '\0' ) + *dst++ = c; + *dst = '\0'; + return dst; +} /* ==================== @@ -2883,7 +2891,7 @@ char *p; int numShaderFiles; int i; - char *oldp, *token, *hashMem; + char *oldp, *token, *hashMem, *textEnd; int shaderTextHashTableSizes[MAX_SHADERTEXT_HASH], hash, size; long sum = 0, summand; @@ -2944,20 +2952,20 @@ // build single large buffer s_shaderText = ri.Hunk_Alloc( sum + numShaderFiles*2, h_low ); s_shaderText[ 0 ] = '\0'; - + textEnd = s_shaderText; + // free in reverse order, so the temp files are all dumped 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" ); - } + if ( !buffers[i] ) + continue; + textEnd = stradd( textEnd, buffers[i] ); + textEnd = stradd( textEnd, "\n" ); + ri.FS_FreeFile( buffers[i] ); } + COM_Compress( s_shaderText ); + // free up memory ri.FS_FreeFileList( shaderFiles );