From 793aadebc501e9eab5215f243c92f657c841931e Mon Sep 17 00:00:00 2001 From: helixhorned Date: Fri, 22 Jul 2011 22:00:53 +0000 Subject: [PATCH] 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 --- polymer/eduke32/build/include/glbuild.h | 1 + polymer/eduke32/build/src/glbuild.c | 3 +++ polymer/eduke32/build/src/mdsprite.c | 2 ++ polymer/eduke32/build/src/polymer.c | 24 ++++++++++++++++++++++++ polymer/eduke32/build/src/polymost.c | 4 ++-- polymer/eduke32/source/gamevars.c | 6 ++++++ polymer/eduke32/source/jmact/scriplib.c | 11 +++++++++++ polymer/eduke32/source/savegame.c | 8 ++++++-- 8 files changed, 55 insertions(+), 4 deletions(-) diff --git a/polymer/eduke32/build/include/glbuild.h b/polymer/eduke32/build/include/glbuild.h index 911c956b8..7582d78d3 100644 --- a/polymer/eduke32/build/include/glbuild.h +++ b/polymer/eduke32/build/include/glbuild.h @@ -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); diff --git a/polymer/eduke32/build/src/glbuild.c b/polymer/eduke32/build/src/glbuild.c index fd5644f4d..438d4697b 100644 --- a/polymer/eduke32/build/src/glbuild.c +++ b/polymer/eduke32/build/src/glbuild.c @@ -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; diff --git a/polymer/eduke32/build/src/mdsprite.c b/polymer/eduke32/build/src/mdsprite.c index 92002bdb2..7197eb62e 100644 --- a/polymer/eduke32/build/src/mdsprite.c +++ b/polymer/eduke32/build/src/mdsprite.c @@ -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); } diff --git a/polymer/eduke32/build/src/polymer.c b/polymer/eduke32/build/src/polymer.c index be8748766..1ec67b47a 100644 --- a/polymer/eduke32/build/src/polymer.c +++ b/polymer/eduke32/build/src/polymer.c @@ -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; ioffset = 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; } diff --git a/polymer/eduke32/source/gamevars.c b/polymer/eduke32/source/gamevars.c index f6519180a..3525ee338 100644 --- a/polymer/eduke32/source/gamevars.c +++ b/polymer/eduke32/source/gamevars.c @@ -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"); diff --git a/polymer/eduke32/source/jmact/scriplib.c b/polymer/eduke32/source/jmact/scriplib.c index 38cb9495b..d9a974a61 100644 --- a/polymer/eduke32/source/jmact/scriplib.c +++ b/polymer/eduke32/source/jmact/scriplib.c @@ -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); } diff --git a/polymer/eduke32/source/savegame.c b/polymer/eduke32/source/savegame.c index d1e3e2da3..2cff0c7a8 100644 --- a/polymer/eduke32/source/savegame.c +++ b/polymer/eduke32/source/savegame.c @@ -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);