light: fix race in allocation of white/coloured lightmap data

Signed-off-by: Kevin Shanahan <kmshanah@disenchant.net>
This commit is contained in:
Kevin Shanahan 2013-03-02 12:18:47 +10:30
parent 9b470d126b
commit 052805c4ca
3 changed files with 17 additions and 28 deletions

View File

@ -52,8 +52,11 @@ extern int sunlight;
extern vec3_t sunlight_color;
extern vec3_t sunvec;
byte *GetFileSpace(int size);
byte *GetLitFileSpace(int size);
/*
* Return space for the lightmap and colourmap at the same time so it can
* be done in a thread-safe manner.
*/
void GetFileSpace(byte **lightdata, byte **colordata, int size);
extern byte *filebase;
extern byte *lit_filebase;

View File

@ -44,43 +44,31 @@ qboolean nominlimit;
qboolean nolightface[MAX_MAP_FACES];
vec3_t faceoffset[MAX_MAP_FACES];
byte *
GetFileSpace(int size)
void
GetFileSpace(byte **lightdata, byte **colordata, int size)
{
byte *buf;
ThreadLock();
/* align to 4 byte boudaries */
file_p = (byte *)(((long)file_p + 3) & ~3);
buf = file_p;
*lightdata = file_p;
file_p += size;
if (colored && colordata) {
/* align to 12 byte boundaries to match offets with 3 * lightdata */
if ((long)lit_file_p % 12)
lit_file_p += 12 - ((long)lit_file_p % 12);
*colordata = lit_file_p;
lit_file_p += size * 3;
}
ThreadUnlock();
if (file_p > file_end)
Error("%s: overrun", __func__);
return buf;
}
byte *
GetLitFileSpace(int size)
{
byte *buf;
ThreadLock();
/* align to 12 byte boundaries (match offets with 3 * GetFileSpace) */
if ((long)lit_file_p % 12)
lit_file_p += 12 - ((long)lit_file_p % 12);
buf = lit_file_p;
lit_file_p += size;
ThreadUnlock();
if (lit_file_p > lit_file_end)
Error("%s: overrun", __func__);
return buf;
}
static void *

View File

@ -1003,9 +1003,7 @@ LightFace(int surfnum, qboolean nolight, const vec3_t faceoffset)
face->styles[i] = l.lightstyles[i];
lightmapsize = size * l.numlightstyles;
out = GetFileSpace(lightmapsize);
if (colored)
lit_out = GetLitFileSpace(lightmapsize * 3);
GetFileSpace(&out, &lit_out, lightmapsize);
face->lightofs = out - filebase;