Skip to content

Commit b3ba232

Browse files
committed
Fix failing to generate depth shader with long name
A shader with a name 58-63 chars long would fail to generate a depth pass shader due to a length check. Add some extra space in the name buffer so this can't happen.
1 parent e079c69 commit b3ba232

2 files changed

Lines changed: 7 additions & 31 deletions

File tree

src/engine/renderer/tr_local.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1132,7 +1132,9 @@ enum
11321132

11331133
struct shader_t
11341134
{
1135-
char name[ MAX_QPATH ]; // game path, including extension
1135+
// max name length is MAX_QPATH - 1 but with room for automatically added suffixes
1136+
char name[ MAX_QPATH + 8 ];
1137+
11361138
int registerFlags; // RSF_
11371139

11381140
int index; // this shader == tr.shaders[index]

src/engine/renderer/tr_shader.cpp

Lines changed: 4 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -5835,17 +5835,6 @@ static void GeneratePermanentShaderTable( const float *values, int numValues )
58355835
shaderTableHashTable[ hash ] = newTable;
58365836
}
58375837

5838-
bool CheckShaderNameLength( const char* func_err, const char* name, const char* suffix )
5839-
{
5840-
if ( strlen( name ) + strlen( suffix ) >= MAX_QPATH )
5841-
{
5842-
Log::Warn("%s Shader name %s%s length longer than MAX_QPATH %d", func_err, name, suffix, MAX_QPATH );
5843-
return false;
5844-
}
5845-
5846-
return true;
5847-
}
5848-
58495838
static void ValidateStage( shaderStage_t *pStage )
58505839
{
58515840
struct stageCheck_t {
@@ -6095,24 +6084,7 @@ static shader_t *FinishShader()
60956084
shader.noFog = true;
60966085
shader.fogShader = nullptr;
60976086

6098-
const char* depthShaderSuffix = "$depth";
6099-
6100-
if ( !CheckShaderNameLength( "FinishShader", shader.name, depthShaderSuffix ) )
6101-
{
6102-
ret->depthShader = nullptr;
6103-
6104-
if ( glConfig.usingMaterialSystem && !tr.worldLoaded ) {
6105-
uint8_t maxStages = ret->lastStage - ret->stages;
6106-
6107-
// Add 1 for potential fog stages
6108-
maxStages = PAD( maxStages + 1, 4 ); // Aligned to 4 components
6109-
materialSystem.maxStages = std::max( maxStages, materialSystem.maxStages );
6110-
}
6111-
6112-
return ret;
6113-
}
6114-
6115-
strcat( shader.name, depthShaderSuffix );
6087+
Q_strcat( shader.name, sizeof( shader.name ), "$depth" );
61166088

61176089
if( stages[0].stateBits & GLS_ATEST_BITS ) {
61186090
// alpha test requires a custom depth shader
@@ -6306,6 +6278,7 @@ shader_t *R_FindShader( const char *name, int flags )
63066278
ClearGlobalShader();
63076279

63086280
Q_strncpyz( shader.name, strippedName, sizeof( shader.name ) );
6281+
ASSERT_LT( strlen( shader.name ), MAX_QPATH );
63096282
shader.registerFlags = flags;
63106283

63116284
for ( i = 0; i < MAX_SHADER_STAGES; i++ )
@@ -6496,8 +6469,9 @@ qhandle_t RE_RegisterShader( const char *name, int flags )
64966469
{
64976470
shader_t *sh;
64986471

6499-
if ( !CheckShaderNameLength( "RE_RegisterShader", name, "" ) )
6472+
if ( strlen( name ) >= MAX_QPATH )
65006473
{
6474+
Log::Warn( "RE_RegisterShader: name '%s' is too long", name );
65016475
return 0;
65026476
}
65036477

0 commit comments

Comments
 (0)