Tutorial *78*

Quake has a major memory leak, LordHavoc discovered it and patched it while working on Nehahra some time ago, and fixes are now in Nehahra, DarkPlaces, QuakeWorld Forever, and QuakeForge. The patch code is below..
Note that it also contains code for fixing texture mismatches, and you thus need to add



int             lhcsum;

to the gltexture_t struct (in gl_draw.c).
The fix is pretty simple, mainly just get rid of the reallocation else :)
== Ender

Find the gl_loadtexture function in gl_draw.c and replace it with the patched version below.


/*

================

GL_LoadTexture

================

*/

int lhcsumtable[256];

int GL_LoadTexture (char *identifier, int width, int height, byte *data, qboolean mipmap, qboolean alpha)

{

 qboolean noalpha;

 int   i, p, s, lhcsum;

 gltexture_t *glt;



 // LordHavoc: do a checksum to confirm the data really is the same as previous

 // occurances. well this isn't exactly a checksum, it's better than that but

 // not following any standards.

 lhcsum = 0;

 s = width*height;

 for (i = 0;i < 256;i++) lhcsumtable[i] = i + 1;

 for (i = 0;i < s;i++) lhcsum += (lhcsumtable[data[i] & 255]++);



 // see if the texture is allready present

 if (identifier[0])

 {

  for (i=0, glt=gltextures ; iidentifier))

   {

    // LordHavoc: everyone hates cache mismatchs, so I fixed it

    if (lhcsum != glt->lhcsum || width != glt->width || height != glt->height)

    {

     Con_DPrintf("GL_LoadTexture: cache mismatch, replacing old texture\n");

     goto GL_LoadTexture_setup; // drop out with glt pointing to the texture to replace

    }

    return glt->texnum;

   }

  }

 }

 // LordHavoc: this was an else condition, causing disasterous results,

 // whoever at id or threewave must've been half asleep...

 glt = &gltextures[numgltextures];

 numgltextures++;



 strcpy (glt->identifier, identifier);

 glt->texnum = texture_extension_number;

 texture_extension_number++;



// LordHavoc: label to drop out of the loop into the setup code

GL_LoadTexture_setup:

 glt->lhcsum = lhcsum; // LordHavoc: used to verify textures are identical

 glt->width = width;

 glt->height = height;

 glt->mipmap = mipmap;



 if (!isDedicated)

 {

         GL_Bind(glt->texnum);

         GL_Upload8 (data, width, height, mipmap, alpha);

 }



 return glt->texnum;

}



 
Sign up
Login:
Passwd:
[Remember Me]