From 517f00663e1c140e6a249f30d0909079bda1978a Mon Sep 17 00:00:00 2001 From: havoc Date: Mon, 7 May 2007 08:46:37 +0000 Subject: [PATCH] reduced uninitialized memory a bit more git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@7246 d7cf8633-e32d-0410-b094-e92efae38249 --- client.h | 5 +++++ gl_rsurf.c | 24 +++++++++++++++++++----- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/client.h b/client.h index 83e48846..78392e93 100644 --- a/client.h +++ b/client.h @@ -999,6 +999,11 @@ typedef struct client_state_s // this is updated to cl.movement_origin whenever health is < 1 // used by %d print in say/say_team messages if cl_locs_enable is on vec3_t lastdeathorigin; + + // processing buffer used by R_BuildLightMap, reallocated as needed, + // freed on each level change + size_t buildlightmapmemorysize; + unsigned char *buildlightmapmemory; } client_state_t; diff --git a/gl_rsurf.c b/gl_rsurf.c index 0cc32001..cd0c3c95 100644 --- a/gl_rsurf.c +++ b/gl_rsurf.c @@ -44,16 +44,30 @@ void R_BuildLightMap (const entity_render_t *ent, msurface_t *surface) int *bl, scale; unsigned char *lightmap, *out, *stain; model_t *model = ent->model; - static int intblocklights[MAX_LIGHTMAP_SIZE*MAX_LIGHTMAP_SIZE*3]; // LordHavoc: *3 for colored lighting - static unsigned char templight[MAX_LIGHTMAP_SIZE*MAX_LIGHTMAP_SIZE*4]; - - // update cached lighting info - surface->cached_dlight = 0; + int *intblocklights; + unsigned char *templight; smax = (surface->lightmapinfo->extents[0]>>4)+1; tmax = (surface->lightmapinfo->extents[1]>>4)+1; size = smax*tmax; size3 = size*3; + + if (cl.buildlightmapmemorysize < size*sizeof(int[3])) + { + cl.buildlightmapmemorysize = size*sizeof(int[3]); + if (cl.buildlightmapmemory) + Mem_Free(cl.buildlightmapmemory); + cl.buildlightmapmemory = Mem_Alloc(cls.levelmempool, cl.buildlightmapmemorysize); + } + + // these both point at the same buffer, templight is only used for final + // processing and can replace the intblocklights data as it goes + intblocklights = (int *)cl.buildlightmapmemory; + templight = (unsigned char *)cl.buildlightmapmemory; + + // update cached lighting info + surface->cached_dlight = 0; + lightmap = surface->lightmapinfo->samples; // set to full bright if no light data -- 2.39.2