fixed crashes when a DL affects a transparent surface with r_lightmap 1

This commit is contained in:
myT 2022-04-14 00:37:00 +02:00
parent a47c8c8dd1
commit f99c223495
3 changed files with 6 additions and 2 deletions

View file

@ -29,6 +29,8 @@ chg: with r_backend GL3, depth fade with MSAA now requires GLSL 4.00 at a minimu
chg: with r_backend GL3, alpha to coverage now requires GLSL 4.00 at a minimum
fix: with r_lightmap 1 and r_dynamiclight 1, lighting transparent surfaces could crash
fix: r_vertexLight 1 no longer applies to non-lightmapped surfaces
fix: delayed shader loads could lead to incorrect rendering and crashes (mostly with dynamic lights)

View file

@ -2339,7 +2339,6 @@ static shader_t* FinishShader()
stages[0].mtStages = 0;
shader.lightingStages[ST_DIFFUSE] = 0; // for working dynamic lights
shader.lightingStages[ST_LIGHTMAP] = 0;
shader.numStages = 1;
}
} else if ( r_lightmap->integer ) {
// now we deal with r_lightmap on a non-opaque shader
@ -2367,6 +2366,9 @@ static shader_t* FinishShader()
for ( int i = 2; i < shader.numStages; ++i ) {
stages[i].active = qfalse;
}
shader.lightingStages[ST_DIFFUSE] = 0; // for working dynamic lights
shader.lightingStages[ST_LIGHTMAP] = 0;
}
}
}

View file

@ -345,7 +345,7 @@ static void R_AddLitSurface( msurface_t* surf, const dlight_t* light )
return; // already in the lit list (or already culled) for this light
const int stageIndex = surf->shader->lightingStages[ST_DIFFUSE];
if ( stageIndex < 0 )
if ( stageIndex < 0 || stageIndex >= surf->shader->numStages )
return;
const shaderStage_t* const stage = surf->shader->stages[stageIndex];