diff --git a/code/renderergl1/tr_image.c b/code/renderergl1/tr_image.c index a926dd82..7a4b1bae 100644 --- a/code/renderergl1/tr_image.c +++ b/code/renderergl1/tr_image.c @@ -1519,6 +1519,7 @@ qhandle_t RE_RegisterSkin( const char *name ) { char *text_p; char *token; char surfName[MAX_QPATH]; + int totalSurfaces; if ( !name || !name[0] ) { ri.Printf( PRINT_DEVELOPER, "Empty name passed to RE_RegisterSkin\n" ); @@ -1569,6 +1570,7 @@ qhandle_t RE_RegisterSkin( const char *name ) { return 0; } + totalSurfaces = 0; text_p = text.c; while ( text_p && *text_p ) { // get surface name @@ -1592,19 +1594,22 @@ qhandle_t RE_RegisterSkin( const char *name ) { // parse the shader name token = CommaParse( &text_p ); - if ( skin->numSurfaces >= MAX_SKIN_SURFACES ) { - ri.Printf( PRINT_WARNING, "WARNING: Ignoring surfaces in '%s', the max is %d surfaces!\n", name, MAX_SKIN_SURFACES ); - break; + if ( skin->numSurfaces < MAX_SKIN_SURFACES ) { + surf = &parseSurfaces[skin->numSurfaces]; + Q_strncpyz( surf->name, surfName, sizeof( surf->name ) ); + surf->shader = R_FindShader( token, LIGHTMAP_NONE, qtrue ); + skin->numSurfaces++; } - surf = &parseSurfaces[skin->numSurfaces]; - Q_strncpyz( surf->name, surfName, sizeof( surf->name ) ); - surf->shader = R_FindShader( token, LIGHTMAP_NONE, qtrue ); - skin->numSurfaces++; + totalSurfaces++; } ri.FS_FreeFile( text.v ); + if ( totalSurfaces > MAX_SKIN_SURFACES ) { + ri.Printf( PRINT_WARNING, "WARNING: Ignoring excess surfaces (found %d, max is %d) in skin '%s'!\n", + totalSurfaces, MAX_SKIN_SURFACES, name ); + } // never let a skin have 0 shaders if ( skin->numSurfaces == 0 ) { diff --git a/code/renderergl2/tr_image.c b/code/renderergl2/tr_image.c index 7340377d..3672910d 100644 --- a/code/renderergl2/tr_image.c +++ b/code/renderergl2/tr_image.c @@ -3071,6 +3071,7 @@ qhandle_t RE_RegisterSkin( const char *name ) { char *text_p; char *token; char surfName[MAX_QPATH]; + int totalSurfaces; if ( !name || !name[0] ) { ri.Printf( PRINT_DEVELOPER, "Empty name passed to RE_RegisterSkin\n" ); @@ -3121,6 +3122,7 @@ qhandle_t RE_RegisterSkin( const char *name ) { return 0; } + totalSurfaces = 0; text_p = text.c; while ( text_p && *text_p ) { // get surface name @@ -3144,19 +3146,22 @@ qhandle_t RE_RegisterSkin( const char *name ) { // parse the shader name token = CommaParse( &text_p ); - if ( skin->numSurfaces >= MAX_SKIN_SURFACES ) { - ri.Printf( PRINT_WARNING, "WARNING: Ignoring surfaces in '%s', the max is %d surfaces!\n", name, MAX_SKIN_SURFACES ); - break; + if ( skin->numSurfaces < MAX_SKIN_SURFACES ) { + surf = &parseSurfaces[skin->numSurfaces]; + Q_strncpyz( surf->name, surfName, sizeof( surf->name ) ); + surf->shader = R_FindShader( token, LIGHTMAP_NONE, qtrue ); + skin->numSurfaces++; } - surf = &parseSurfaces[skin->numSurfaces]; - Q_strncpyz( surf->name, surfName, sizeof( surf->name ) ); - surf->shader = R_FindShader( token, LIGHTMAP_NONE, qtrue ); - skin->numSurfaces++; + totalSurfaces++; } ri.FS_FreeFile( text.v ); + if ( totalSurfaces > MAX_SKIN_SURFACES ) { + ri.Printf( PRINT_WARNING, "WARNING: Ignoring excess surfaces (found %d, max is %d) in skin '%s'!\n", + totalSurfaces, MAX_SKIN_SURFACES, name ); + } // never let a skin have 0 shaders if ( skin->numSurfaces == 0 ) {