Skip to content

Commit 2e2055f

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 276222a commit 2e2055f

File tree

2 files changed

+7
-31
lines changed

2 files changed

+7
-31
lines changed

src/engine/renderer/tr_local.h

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

11311131
struct shader_t
11321132
{
1133-
char name[ MAX_QPATH ]; // game path, including extension
1133+
// max name length is MAX_QPATH - 1 but with room for automatically added suffixes
1134+
char name[ MAX_QPATH + 8 ];
1135+
11341136
int registerFlags; // RSF_
11351137

11361138
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
@@ -5818,17 +5818,6 @@ static void GeneratePermanentShaderTable( const float *values, int numValues )
58185818
shaderTableHashTable[ hash ] = newTable;
58195819
}
58205820

5821-
bool CheckShaderNameLength( const char* func_err, const char* name, const char* suffix )
5822-
{
5823-
if ( strlen( name ) + strlen( suffix ) >= MAX_QPATH )
5824-
{
5825-
Log::Warn("%s Shader name %s%s length longer than MAX_QPATH %d", func_err, name, suffix, MAX_QPATH );
5826-
return false;
5827-
}
5828-
5829-
return true;
5830-
}
5831-
58325821
static void ValidateStage( shaderStage_t *pStage )
58335822
{
58345823
struct stageCheck_t {
@@ -6078,24 +6067,7 @@ static shader_t *FinishShader()
60786067
shader.noFog = true;
60796068
shader.fogShader = nullptr;
60806069

6081-
const char* depthShaderSuffix = "$depth";
6082-
6083-
if ( !CheckShaderNameLength( "FinishShader", shader.name, depthShaderSuffix ) )
6084-
{
6085-
ret->depthShader = nullptr;
6086-
6087-
if ( glConfig.usingMaterialSystem && !tr.worldLoaded ) {
6088-
uint8_t maxStages = ret->lastStage - ret->stages;
6089-
6090-
// Add 1 for potential fog stages
6091-
maxStages = PAD( maxStages + 1, 4 ); // Aligned to 4 components
6092-
materialSystem.maxStages = std::max( maxStages, materialSystem.maxStages );
6093-
}
6094-
6095-
return ret;
6096-
}
6097-
6098-
strcat( shader.name, depthShaderSuffix );
6070+
Q_strcat( shader.name, sizeof( shader.name ), "$depth" );
60996071

61006072
if( stages[0].stateBits & GLS_ATEST_BITS ) {
61016073
// alpha test requires a custom depth shader
@@ -6284,6 +6256,7 @@ shader_t *R_FindShader( const char *name, int flags )
62846256
ClearGlobalShader();
62856257

62866258
Q_strncpyz( shader.name, strippedName, sizeof( shader.name ) );
6259+
ASSERT_LT( strlen( shader.name ), MAX_QPATH );
62876260
shader.registerFlags = flags;
62886261

62896262
for ( i = 0; i < MAX_SHADER_STAGES; i++ )
@@ -6474,8 +6447,9 @@ qhandle_t RE_RegisterShader( const char *name, int flags )
64746447
{
64756448
shader_t *sh;
64766449

6477-
if ( !CheckShaderNameLength( "RE_RegisterShader", name, "" ) )
6450+
if ( strlen( name ) >= MAX_QPATH )
64786451
{
6452+
Log::Warn( "RE_RegisterShader: name '%s' is too long", name );
64796453
return 0;
64806454
}
64816455

0 commit comments

Comments
 (0)