- started fixing memory leaks: Console and clip shapes done.

This commit is contained in:
Christoph Oelckers 2019-12-24 16:09:43 +01:00
parent 58d0585eaa
commit 0d908960ed
7 changed files with 16 additions and 34 deletions

View file

@ -1108,9 +1108,7 @@ int32_t md_loadmodel(const char *fn);
int32_t md_setmisc(int32_t modelid, float scale, int32_t shadeoff, float zadd, float yoffset, int32_t flags);
// int32_t md_tilehasmodel(int32_t tilenume, int32_t pal);
#ifdef HAVE_CLIPSHAPE_FEATURE
extern GrowArray<char *> g_clipMapFiles;
#endif
extern TArray<FString> g_clipMapFiles;
EXTERN int32_t nextvoxid;
EXTERN intptr_t voxoff[MAXVOXELS][MAXVOXMIPS]; // used in KenBuild

View file

@ -26,7 +26,6 @@ static int16_t clipobjectval[MAXCLIPNUM];
static uint8_t clipignore[(MAXCLIPNUM+7)>>3];
////// sector-like clipping for sprites //////
#ifdef HAVE_CLIPSHAPE_FEATURE
void engineSetClipMap(mapinfo_t *bak, mapinfo_t *newmap)
{
if (bak)
@ -63,9 +62,7 @@ static uwalltype *loadwall, *loadwallinv;
static uspritetype *loadsprite;
vec2_t hitscangoal = { (1<<29)-1, (1<<29)-1 };
#ifdef USE_OPENGL
int32_t hitallsprites = 0;
#endif
void engineInitClipMaps()
{
@ -96,7 +93,7 @@ int32_t engineLoadClipMaps(void)
int32_t lwcp = 0;
size_t fi;
size_t const g_clipMapFilesNum = g_clipMapFiles.size();
size_t const g_clipMapFilesNum = g_clipMapFiles.Size();
int32_t *fisec = NULL;
int32_t *fispr = NULL;
@ -129,13 +126,13 @@ int32_t engineLoadClipMaps(void)
continue;
// Numsprites will now be set!
initprintf("Loading clip map: %s\n", g_clipMapFiles[fi]);
initprintf("Loading clip map: %s\n", g_clipMapFiles[fi].GetChars());
if (ournumsectors+numsectors>MAXSECTORS ||
ournumwalls+numwalls>MAXWALLS ||
ournumsprites+Numsprites>MAXSPRITES)
{
initprintf("clip map: warning: exceeded limits when loading %s, aborting.\n", g_clipMapFiles[fi]);
initprintf("clip map: warning: exceeded limits when loading %s, aborting.\n", g_clipMapFiles[fi].GetChars());
break;
}
@ -251,7 +248,7 @@ int32_t engineLoadClipMaps(void)
if (k>=fisec[fi])
break;
initprintf("clip map \"%s\": error: tried to chain picnum %d (sprite %d) in sector %d which"
" already belongs to picnum %d.\n", g_clipMapFiles[fi], pn, i-fispr[fi], k-fisec[fi],
" already belongs to picnum %d.\n", g_clipMapFiles[fi].GetChars(), pn, i-fispr[fi], k-fisec[fi],
clipinfo[sectoidx[k]].picnum);
engineInitClipMaps();
@ -279,7 +276,7 @@ int32_t engineLoadClipMaps(void)
if (i>=fispr[fi])
break;
initprintf("clip map \"%s\": warning: sprite %d pointing neither northward nor southward. %s will be wrong.\n",
g_clipMapFiles[fi], i-fispr[fi], (sprite[i].cstat&48)==32 ? "Scaling and flipping" : "X-flipping");
g_clipMapFiles[fi].GetChars(), i-fispr[fi], (sprite[i].cstat&48)==32 ? "Scaling and flipping" : "X-flipping");
}
}
@ -316,7 +313,7 @@ int32_t engineLoadClipMaps(void)
if (ns>=fisec[fi])
break;
initprintf("clip map \"%s\": error: encountered more than one outer sector (%d and %d)"
" for sprite %d.\n", g_clipMapFiles[fi], outersect-fisec[fi], ns-fisec[fi], i-fispr[fi]);
" for sprite %d.\n", g_clipMapFiles[fi].GetChars(), outersect-fisec[fi], ns-fisec[fi], i-fispr[fi]);
engineInitClipMaps();
Xfree(fisec);
@ -335,7 +332,7 @@ int32_t engineLoadClipMaps(void)
break;
initprintf("clip map \"%s\": error: encountered sector %d belonging to index %d"
" while collecting sectors for sprite %d (index %d).\n",
g_clipMapFiles[fi], ns-fisec[fi], sectoidx[ns], i-fispr[fi], numclipmaps);
g_clipMapFiles[fi].GetChars(), ns-fisec[fi], sectoidx[ns], i-fispr[fi], numclipmaps);
engineInitClipMaps();
Xfree(fisec);
@ -535,15 +532,6 @@ int clipshape_idx_for_sprite(uspriteptr_t const curspr, int curidx)
return curidx;
}
#else
int32_t clipshape_idx_for_sprite(uspriteptr_t const curspr, int32_t curidx)
{
(void)curspr;
UNREFERENCED_PARAMETER(curidx);
return -1;
}
#endif // HAVE_CLIPSHAPE_FEATURE
////// //////
////////// CLIPMOVE //////////

View file

@ -12,7 +12,7 @@
// def/clipmap handling
#ifdef HAVE_CLIPSHAPE_FEATURE
GrowArray<char *> g_clipMapFiles;
TArray<FString> g_clipMapFiles;
#endif
void SetClipshapes()
@ -24,7 +24,7 @@ void SetClipshapes()
char clipshape[16] = "_clipshape0.map";
clipshape[10] = j;
g_clipMapFiles.append(Xstrdup(clipshape));
g_clipMapFiles.Push(clipshape);
}
#endif
}
@ -32,7 +32,7 @@ void SetClipshapes()
#ifdef HAVE_CLIPSHAPE_FEATURE
void G_AddClipMap(const char *buffer)
{
g_clipMapFiles.append(Xstrdup(buffer));
g_clipMapFiles.Push(buffer);
}
#endif

View file

@ -313,9 +313,11 @@ int GameMain()
}
ShutdownSystem();
G_SaveConfig();
C_DeinitConsole();
#ifndef NETCODE_DISABLE
if (gHaveNetworking) enet_deinitialize();
#endif
if (Args) delete Args;
return r;
}

View file

@ -5880,15 +5880,11 @@ int GameInterface::app_main()
registerosdcommands();
#ifdef HAVE_CLIPSHAPE_FEATURE
int const clipMapError = engineLoadClipMaps();
if (clipMapError > 0)
initprintf("There was an error loading the sprite clipping map (status %d).\n", clipMapError);
for (char * m : g_clipMapFiles)
free(m);
g_clipMapFiles.clear();
#endif
g_clipMapFiles.Reset();
if (g_networkMode != NET_DEDICATED_SERVER)
{

View file

@ -1172,7 +1172,7 @@ int WINAPI wWinMain (HINSTANCE hInstance, HINSTANCE nothing, LPWSTR cmdline, int
_CrtSetDbgFlag (_CrtSetDbgFlag(0) | _CRTDBG_LEAK_CHECK_DF);
// Use this to break at a specific allocation number.
//_crtBreakAlloc = 227524;
//_crtBreakAlloc = 167;
#endif
int ret = DoMain (hInstance);

View file

@ -7341,9 +7341,7 @@ int GameInterface::app_main()
if (clipMapError > 0)
initprintf("There was an error loading the sprite clipping map (status %d).\n", clipMapError);
for (char * m : g_clipMapFiles)
free(m);
g_clipMapFiles.clear();
g_clipMapFiles.Reset();
#endif
V_Init2();