From 57583cc88d7a6f3c9d0dc9c4b695c7b9e97b9210 Mon Sep 17 00:00:00 2001 From: havoc Date: Sun, 11 Sep 2005 12:02:02 +0000 Subject: [PATCH] fix a crash on vertex lighting q1bsp/hlbsp surfaces with no lightmap samples data git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@5721 d7cf8633-e32d-0410-b094-e92efae38249 --- gl_rmain.c | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/gl_rmain.c b/gl_rmain.c index 14d17f72..deaa8db4 100644 --- a/gl_rmain.c +++ b/gl_rmain.c @@ -1665,27 +1665,32 @@ void RSurf_SetColorPointer(const entity_render_t *ent, const msurface_t *surface for (i = 0, c = varray_color4f + 4 * surface->num_firstvertex;i < surface->num_vertices;i++, c += 4) { const qbyte *lm = surface->lightmapinfo->samples + (surface->groupmesh->data_lightmapoffsets + surface->num_firstvertex)[i]; - float scale = d_lightstylevalue[surface->lightmapinfo->styles[0]] * (1.0f / 32768.0f); - VectorScale(lm, scale, c); - if (surface->lightmapinfo->styles[1] != 255) + if (lm) { - int size3 = ((surface->lightmapinfo->extents[0]>>4)+1)*((surface->lightmapinfo->extents[1]>>4)+1)*3; - lm += size3; - scale = d_lightstylevalue[surface->lightmapinfo->styles[1]] * (1.0f / 32768.0f); - VectorMA(c, scale, lm, c); - if (surface->lightmapinfo->styles[2] != 255) + float scale = d_lightstylevalue[surface->lightmapinfo->styles[0]] * (1.0f / 32768.0f); + VectorScale(lm, scale, c); + if (surface->lightmapinfo->styles[1] != 255) { + int size3 = ((surface->lightmapinfo->extents[0]>>4)+1)*((surface->lightmapinfo->extents[1]>>4)+1)*3; lm += size3; - scale = d_lightstylevalue[surface->lightmapinfo->styles[2]] * (1.0f / 32768.0f); + scale = d_lightstylevalue[surface->lightmapinfo->styles[1]] * (1.0f / 32768.0f); VectorMA(c, scale, lm, c); - if (surface->lightmapinfo->styles[3] != 255) + if (surface->lightmapinfo->styles[2] != 255) { lm += size3; - scale = d_lightstylevalue[surface->lightmapinfo->styles[3]] * (1.0f / 32768.0f); + scale = d_lightstylevalue[surface->lightmapinfo->styles[2]] * (1.0f / 32768.0f); VectorMA(c, scale, lm, c); + if (surface->lightmapinfo->styles[3] != 255) + { + lm += size3; + scale = d_lightstylevalue[surface->lightmapinfo->styles[3]] * (1.0f / 32768.0f); + VectorMA(c, scale, lm, c); + } } } } + else + VectorClear(c); } rsurface_lightmapcolor4f = varray_color4f; } -- 2.39.2