From c2bac6d1ef88aa1e85d1353e76e98037d003b951 Mon Sep 17 00:00:00 2001 From: smallmodel <15067410+smallmodel@users.noreply.github.com> Date: Sun, 19 Jan 2025 15:16:35 +0100 Subject: [PATCH] Prevent lightmapIndex from going below LIGHTMAP_2D --- code/renderergl1/tr_shader.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/code/renderergl1/tr_shader.c b/code/renderergl1/tr_shader.c index 61de647b..0ba971e7 100644 --- a/code/renderergl1/tr_shader.c +++ b/code/renderergl1/tr_shader.c @@ -3362,6 +3362,10 @@ shader_t* R_FindShader(const char* name, int lightmapIndex, qboolean mipRawImage // lightmaps if ( lightmapIndex >= 0 && lightmapIndex >= tr.numLightmaps ) { lightmapIndex = LIGHTMAP_BY_VERTEX; + } else if ( lightmapIndex < LIGHTMAP_2D ) { + // negative lightmap indexes cause stray pointers (think tr.lightmaps[lightmapIndex]) + ri.Printf( PRINT_WARNING, "WARNING: shader '%s' has invalid lightmap index of %d\n", name, lightmapIndex ); + lightmapIndex = LIGHTMAP_BY_VERTEX; } COM_StripExtension( name, strippedName, sizeof(strippedName));