From 0e5438ab1488a52e0578b40e63c3f3a3a5ba5bc5 Mon Sep 17 00:00:00 2001 From: Eric Wasylishen Date: Tue, 7 Jun 2016 20:26:19 -0600 Subject: [PATCH] light: fix saving bogus lightmaps for non-lightmapped faces when -bounce is in use --- include/light/light.h | 2 +- light/ltface.c | 43 ++++++++++++++++++++++++++++--------------- 2 files changed, 29 insertions(+), 16 deletions(-) diff --git a/include/light/light.h b/include/light/light.h index 87d8c94d..76dab472 100644 --- a/include/light/light.h +++ b/include/light/light.h @@ -157,7 +157,7 @@ typedef struct { struct ltface_ctx { const bsp2_t *bsp; - lightsurf_t lightsurf; + lightsurf_t *lightsurf; lightmap_t lightmaps[MAXLIGHTMAPS + 1]; }; diff --git a/light/ltface.c b/light/ltface.c index 20f906ba..8a9ae26e 100644 --- a/light/ltface.c +++ b/light/ltface.c @@ -2070,20 +2070,25 @@ void LightFaceShutdown(struct ltface_ctx *ctx) free(ctx->lightmaps[i].samples); } - if (ctx->lightsurf.points) - free(ctx->lightsurf.points); + if (!ctx->lightsurf) + return; - if (ctx->lightsurf.normals) - free(ctx->lightsurf.normals); + if (ctx->lightsurf->points) + free(ctx->lightsurf->points); - if (ctx->lightsurf.occlusion) - free(ctx->lightsurf.occlusion); + if (ctx->lightsurf->normals) + free(ctx->lightsurf->normals); - if (ctx->lightsurf.occluded) - free(ctx->lightsurf.occluded); + if (ctx->lightsurf->occlusion) + free(ctx->lightsurf->occlusion); - if (ctx->lightsurf.pvs) - free(ctx->lightsurf.pvs); + if (ctx->lightsurf->occluded) + free(ctx->lightsurf->occluded); + + if (ctx->lightsurf->pvs) + free(ctx->lightsurf->pvs); + + free(ctx->lightsurf); } const char * @@ -2115,7 +2120,6 @@ LightFace(bsp2_dface_t *face, facesup_t *facesup, const modelinfo_t *modelinfo, const bsp2_t *bsp = ctx->bsp; lightmap_t *lightmaps = ctx->lightmaps; - lightsurf_t *lightsurf = &ctx->lightsurf; const char *texname = Face_TextureName(bsp, face); /* One extra lightmap is allocated to simplify handling overflow */ @@ -2129,9 +2133,9 @@ LightFace(bsp2_dface_t *face, facesup_t *facesup, const modelinfo_t *modelinfo, } else { - face->lightofs = -1; - for (i = 0; i < MAXLIGHTMAPS; i++) - face->styles[i] = 255; + face->lightofs = -1; + for (i = 0; i < MAXLIGHTMAPS; i++) + face->styles[i] = 255; } if (bsp->texinfo[face->texinfo].flags & TEX_SPECIAL) return; @@ -2144,6 +2148,11 @@ LightFace(bsp2_dface_t *face, facesup_t *facesup, const modelinfo_t *modelinfo, if (!Q_strcasecmp(texname, "skip")) return; + /* all good, this face is going to be lightmapped. */ + ctx->lightsurf = (lightsurf_t *) calloc(1, sizeof(lightsurf_t)); + lightsurf_t *lightsurf = ctx->lightsurf; + + /* if liquid doesn't have the TEX_SPECIAL flag set, the map was qbsp'ed with * lit water in mind. In that case receive light from both top and bottom. * (lit will only be rendered in compatible engines, but degrades gracefully.) @@ -2281,7 +2290,11 @@ void LightFaceIndirect(bsp2_dface_t *face, facesup_t *facesup, const modelinfo_t *modelinfo, struct ltface_ctx *ctx) { lightmap_t *lightmaps = ctx->lightmaps; - lightsurf_t *lightsurf = &ctx->lightsurf; + lightsurf_t *lightsurf = ctx->lightsurf; + + if (lightsurf == NULL) + return; /* this face is not lightmapped */ + if (debugmode == debugmode_bounce) { Lightmap_ClearAll(lightmaps);