From 03435446b4194feafa17ad235ff9acf448d89e47 Mon Sep 17 00:00:00 2001 From: Shpoike Date: Tue, 13 Jul 2021 06:20:09 +0100 Subject: [PATCH] Don't bug out when a bmodel is late cached (just rebuild all the things to deal with it). --- Quake/cl_parse.c | 3 +++ Quake/r_brush.c | 66 +++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 63 insertions(+), 6 deletions(-) diff --git a/Quake/cl_parse.c b/Quake/cl_parse.c index c9cc5255..3f7340cc 100644 --- a/Quake/cl_parse.c +++ b/Quake/cl_parse.c @@ -2047,6 +2047,9 @@ static void CL_ParsePrecache(void) cl.model_precache[index] = Mod_ForName (name, false); //FIXME: if its a bsp model, generate lightmaps. //FIXME: update static entities with that modelindex + + if (cl.model_precache[index]) + GL_BuildModel(cl.model_precache[index]); } break; #ifdef PSET_SCRIPT diff --git a/Quake/r_brush.c b/Quake/r_brush.c index 8c050b04..f5f8b30d 100644 --- a/Quake/r_brush.c +++ b/Quake/r_brush.c @@ -29,6 +29,7 @@ extern cvar_t gl_zfix; // QuakeSpasm z-fighting fix int gl_lightmap_format; int lightmap_bytes; +qboolean lightmaps_latecached; #define MAX_SANITY_LIGHTMAPS (1u<<20) struct lightmap_s *lightmap; @@ -731,8 +732,15 @@ int AllocBlock (int w, int h, int *x, int *y) /* FIXME: we leave 'gaps' in malloc()ed data, CRC_Block() later accesses * that uninitialized data and valgrind complains for it. use calloc() ? */ lightmap[texnum].data = (byte *) malloc(4*LMBLOCK_WIDTH*LMBLOCK_HEIGHT); + memset(lightmap[texnum].data, 0, 4*LMBLOCK_WIDTH*LMBLOCK_HEIGHT); //as we're only tracking one texture, we don't need multiple copies of allocated any more. memset(allocated, 0, sizeof(allocated)); + + lightmap[texnum].modified = true; + lightmap[texnum].rectchange.l = 0; + lightmap[texnum].rectchange.t = 0; + lightmap[texnum].rectchange.h = LMBLOCK_HEIGHT; + lightmap[texnum].rectchange.w = LMBLOCK_WIDTH; } best = LMBLOCK_HEIGHT; @@ -887,6 +895,9 @@ void GL_BuildModel (qmodel_t *m) //johnfitz } + if (m->type == mod_brush) + lightmaps_latecached=true; + // GL_BuildBModelVertexBuffer(); } @@ -909,7 +920,11 @@ void GL_BuildLightmaps (void) //Spike -- wipe out all the lightmap data (johnfitz -- the gltexture objects were already freed by Mod_ClearAll) for (i=0; i < lightmap_count; i++) + { + if (lightmap[i].texture) + TexMgr_FreeTexture(lightmap[i].texture); free(lightmap[i].data); + } free(lightmap); lightmap = NULL; last_lightmap_allocated = 0; @@ -933,7 +948,7 @@ void GL_BuildLightmaps (void) { m = cl.model_precache[j]; if (!m) - break; + continue; GL_BuildModel(m); } for (j=1 ; j