Janitorial work part 2, perfect for a rainy day. This fixes a lot of leaks, both on the client side as well as for memory allocated by OpenGL. If you had crashes after a few times of restartvid'ing in Polymer, this should fix it.

git-svn-id: https://svn.eduke32.com/eduke32@1942 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
helixhorned 2011-07-22 22:00:53 +00:00
parent d4f234b09f
commit 793aadebc5
8 changed files with 55 additions and 4 deletions

View file

@ -293,6 +293,7 @@ extern void (APIENTRY * bgluTessNormal) (GLUtesselator* tess, GLdoub
extern void (APIENTRY * bgluTessProperty) (GLUtesselator* tess, GLenum which, GLdouble data);
extern void (APIENTRY * bgluTessVertex) (GLUtesselator* tess, GLdouble *location, GLvoid* data);
extern GLUtesselator* (APIENTRY * bgluNewTess) (void);
extern void (APIENTRY * bgluDeleteTess) (GLUtesselator* tess);
extern void (APIENTRY * bgluPerspective) (GLdouble fovy, GLdouble aspect, GLdouble zNear, GLdouble zFar);

View file

@ -260,6 +260,7 @@ void (APIENTRY *bgluTessNormal)(GLUtesselator *tess, GLdouble valueX, GLdouble v
void (APIENTRY *bgluTessProperty)(GLUtesselator *tess, GLenum which, GLdouble data);
void (APIENTRY *bgluTessVertex)(GLUtesselator *tess, GLdouble *location, GLvoid *data);
GLUtesselator *(APIENTRY *bgluNewTess)(void);
void (APIENTRY * bgluDeleteTess)(GLUtesselator *tess);
void (APIENTRY *bgluPerspective)(GLdouble fovy, GLdouble aspect, GLdouble zNear, GLdouble zFar);
@ -944,6 +945,7 @@ int32_t loadglulibrary(const char *driver)
bgluTessProperty = GLUGETPROC("gluTessProperty");
bgluTessVertex = GLUGETPROC("gluTessVertex");
bgluNewTess = GLUGETPROC("gluNewTess");
bgluDeleteTess = GLUGETPROC("gluDeleteTess");
bgluPerspective = GLUGETPROC("gluPerspective");
@ -986,6 +988,7 @@ int32_t unloadglulibrary(void)
bgluTessProperty = NULL;
bgluTessVertex = NULL;
bgluNewTess = NULL;
bgluDeleteTess = NULL;
bgluPerspective = NULL;

View file

@ -2486,6 +2486,8 @@ static void md3free(md3model_t *m)
if (s->xyzn) Bfree(s->xyzn);
if (s->geometry) Bfree(s->geometry);
}
else
if (s->geometry) Bfree(s->geometry); // ?
}
Bfree(m->head.surfs);
}

View file

@ -648,9 +648,14 @@ int32_t polymer_init(void)
return (0);
}
polymer_freeboard();
Bmemset(&prsectors[0], 0, sizeof(prsectors[0]) * MAXSECTORS);
Bmemset(&prwalls[0], 0, sizeof(prwalls[0]) * MAXWALLS);
if (prtess)
bgluDeleteTess(prtess);
prtess = bgluNewTess();
if (prtess == 0)
{
@ -698,6 +703,9 @@ int32_t polymer_init(void)
{
if (prhighpalookups[i][j].data)
{
if (prhighpalookups[i][j].map)
bglDeleteTextures(1, &prhighpalookups[i][j].map);
bglGenTextures(1, &prhighpalookups[i][j].map);
bglBindTexture(GL_TEXTURE_3D, prhighpalookups[i][j].map);
bglTexImage3D(GL_TEXTURE_3D, // target
@ -2225,6 +2233,7 @@ static void polymer_freeboard(void)
{
if (prwalls[i]->bigportal) Bfree(prwalls[i]->bigportal);
if (prwalls[i]->mask.buffer) Bfree(prwalls[i]->mask.buffer);
if (prwalls[i]->over.buffer) Bfree(prwalls[i]->over.buffer);
if (prwalls[i]->cap) Bfree(prwalls[i]->cap);
if (prwalls[i]->wall.buffer) Bfree(prwalls[i]->wall.buffer);
if (prwalls[i]->wall.vbo) bglDeleteBuffersARB(1, &prwalls[i]->wall.vbo);
@ -5331,6 +5340,21 @@ static void polymer_initrendertargets(int32_t count)
{
int32_t i;
static int32_t ocount;
if (prrts)
{
for (i=0; i<ocount; i++)
{
if (!i)
bglDeleteTextures(1, &prrts[i].color);
bglDeleteTextures(1, &prrts[i].z);
bglDeleteFramebuffersEXT(1, &prrts[i].fbo);
}
Bfree(prrts);
}
ocount = count;
prrts = Bcalloc(count, sizeof(_prrt));
i = 0;

View file

@ -1318,7 +1318,7 @@ static int32_t LoadCacheOffsets(void)
curcacheindex->offset = foffset;
curcacheindex->len = fsize;
curcacheindex->next = (texcacheindex *)Bcalloc(1, sizeof(texcacheindex));
hash_add(&h_texcache, Bstrdup(fname), numcacheentries, 1);
hash_add(&h_texcache, fname, numcacheentries, 1);
cacheptrs[numcacheentries++] = curcacheindex;
curcacheindex = curcacheindex->next;
}
@ -1559,7 +1559,7 @@ void writexcache(char *fn, int32_t len, int32_t dameth, char effect, texcachehea
}
else OSD_Printf("wtf?\n");
hash_add(&h_texcache, Bstrdup(cachefn), numcacheentries, 0);
hash_add(&h_texcache, cachefn, numcacheentries, 0);
cacheptrs[numcacheentries++] = curcacheindex;
curcacheindex = curcacheindex->next;
}

View file

@ -1552,6 +1552,12 @@ void Gv_Init(void)
{
// only call ONCE
// (... not true anymore)
static int32_t inited=0;
if (inited)
return;
inited = 1;
// initprintf("Initializing game variables\n");
//AddLog("Gv_Init");

View file

@ -101,10 +101,21 @@ void SCRIPT_FreeSection(ScriptSectionType * section)
while (section->entries->nextentry != section->entries)
{
e = section->entries->nextentry;
if (section->entries->name)
Bfree(section->entries->name);
if (section->entries->value)
Bfree(section->entries->value);
Bfree(section->entries);
section->entries = e;
}
if (section->entries->name)
Bfree(section->entries->name);
if (section->entries->value)
Bfree(section->entries->value);
Bfree(section->entries);
Bfree(section->name);
}

View file

@ -304,7 +304,7 @@ int32_t G_LoadPlayer(int32_t spot)
if (kdfread(&g_scriptSize,sizeof(g_scriptSize),1,fil) != 1) goto corrupt;
if (!g_scriptSize) goto corrupt;
scriptptrs = Bcalloc(1,g_scriptSize * sizeof(scriptptrs));
// scriptptrs = Bcalloc(1,g_scriptSize * sizeof(scriptptrs));
Bfree(bitptr);
bitptr = Bcalloc(1,(((g_scriptSize+7)>>3)+1) * sizeof(uint8_t));
if (kdfread(&bitptr[0],sizeof(uint8_t),(g_scriptSize+7)>>3,fil) != ((g_scriptSize+7)>>3)) goto corrupt;
@ -334,7 +334,7 @@ int32_t G_LoadPlayer(int32_t spot)
actorLoadEventScrptr[i] = (intptr_t *)j;
}
scriptptrs = Brealloc(scriptptrs, MAXSPRITES * sizeof(scriptptrs));
scriptptrs = Bmalloc(MAXSPRITES * sizeof(scriptptrs));
if (kdfread(&scriptptrs[0],sizeof(scriptptrs),MAXSPRITES,fil) != MAXSPRITES) goto corrupt;
if (kdfread(&actor[0],sizeof(actor_t),MAXSPRITES,fil) != MAXSPRITES) goto corrupt;
@ -348,6 +348,8 @@ int32_t G_LoadPlayer(int32_t spot)
actor[i].projectile = &SpriteProjectile[i];
}
Bfree(scriptptrs);
if (kdfread(&lockclock,sizeof(lockclock),1,fil) != 1) goto corrupt;
if (kdfread(&pskybits,sizeof(pskybits),1,fil) != 1) goto corrupt;
if (kdfread(&pskyoff[0],sizeof(pskyoff[0]),MAXPSKYTILES,fil) != MAXPSKYTILES) goto corrupt;
@ -843,6 +845,8 @@ int32_t G_SavePlayer(int32_t spot)
T6 += j;
}
Bfree(scriptptrs);
dfwrite(&lockclock,sizeof(lockclock),1,fil);
dfwrite(&pskybits,sizeof(pskybits),1,fil);
dfwrite(&pskyoff[0],sizeof(pskyoff[0]),MAXPSKYTILES,fil);