Skip to content

Commit

Permalink
Fix even mopre memory leaks
Browse files Browse the repository at this point in the history
  • Loading branch information
MadDeCoDeR committed Oct 24, 2023
1 parent 70f29d8 commit 1cf31f4
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 2 deletions.
23 changes: 23 additions & 0 deletions doomclassic/doom/doomlib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,17 @@ fixed_t GetViewY()
return ::g->viewy + ::g->viewyoffset;
}

template<class T>
void CleanVector(std::vector<T*> myVector) {
for (int i = 0; i < myVector.size(); i++) {
if (myVector[i] != NULL) {
void* val = myVector[i];
myVector[i] = NULL;
delete val;
}
}
}

void DoomLib::Shutdown() {
//GK: Reset Dehacked patches also here just in case
/*resetValues();
Expand All @@ -453,6 +464,18 @@ void DoomLib::Shutdown() {
if ( globaldata[currentplayer] ) {
Globals* glob = globaldata[currentplayer];
globaldata[currentplayer] = NULL;
CleanVector(glob->activeceilings);
CleanVector(glob->activeplats);
CleanVector(glob->intercepts);
CleanVector(glob->drawsegs);
CleanVector(glob->sprites);
CleanVector(glob->vissprites);
CleanVector(glob->cpatch);
CleanVector(glob->visplanes);
CleanVector(glob->reverbs);
for (int j = 0; j < glob->acts.size(); j++) {
CleanVector(glob->acts[j]);
}
delete glob;
}
}
Expand Down
4 changes: 4 additions & 0 deletions doomclassic/doom/p_ceilng.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -325,9 +325,13 @@ void P_RemoveActiveCeiling(ceiling_t* c)
{
if (::g->activeceilings[i] == c)
{
void* tempData = ::g->activeceilings[i]->sector->ceilingdata;
::g->activeceilings[i]->sector->ceilingdata = NULL;
Z_Free(tempData);
P_RemoveThinker (&::g->activeceilings[i]->thinker);
ceiling_t* tempCeiling = ::g->activeceilings[i];
::g->activeceilings[i] = NULL;
Z_Free(tempCeiling);
//::g->cellind = ::g->cellind - 1;
break;
}
Expand Down
9 changes: 9 additions & 0 deletions doomclassic/doom/p_maputl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -929,10 +929,19 @@ P_PathTraverse

void AddNewIntercept() {
if (::g->interind >= ::g->intercepts.size()) {
#if _ITERATOR_DEBUG_LEVEL < 2
if (::g->intercepts.size() == ::g->intercepts.capacity()) {
::g->intercepts.reserve(::g->intercepts.size() + MAXINTERCEPTS);
}
::g->intercepts.emplace_back(new intercept_t());
#else
if (::g->intercepts.size() == ::g->intercepts.capacity()) {
::g->intercepts.resize(::g->intercepts.size() + MAXINTERCEPTS);
}
for (int j = ::g->interind; j < ::g->intercepts.size(); j++) {
::g->intercepts[j] = new intercept_t();
}
#endif
}
else {
::g->intercepts[::g->interind]->d.line = NULL;
Expand Down
8 changes: 6 additions & 2 deletions doomclassic/doom/p_spec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2026,7 +2026,9 @@ void P_SpawnSpecials (void)
if (::g->activeceilings.size() == ::g->activeceilings.capacity()) {
::g->activeceilings.resize(::g->activeceilings.size() + MAXCEILINGS);
}
::g->activeceilings[::g->cellind] = new ceiling_t();
for (int ci = ::g->cellind; ci < ::g->activeceilings.size(); ci++) {
::g->activeceilings[ci] = new ceiling_t();
}
#endif
}
::g->cellind++;
Expand All @@ -2041,7 +2043,9 @@ void P_SpawnSpecials (void)
if (::g->activeplats.size() == ::g->activeplats.capacity()) {
::g->activeplats.resize(::g->activeplats.size() + MAXPLATS);
}
::g->activeplats[::g->platind] = new plat_t();
for (int pi = ::g->platind; pi < ::g->activeplats.size(); pi++) {
::g->activeplats[pi] = new plat_t();
}
#endif
}
::g->platind++;
Expand Down
9 changes: 9 additions & 0 deletions doomclassic/doom/r_things.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -373,10 +373,19 @@ vissprite_t* R_NewVisSprite (void)
//return &::g->overflowsprite;

if (::g->visspriteind >= ::g->vissprites.size()) {
#if _ITERATOR_DEBUG_LEVEL < 2
if (::g->vissprites.size() == ::g->vissprites.capacity()) {
::g->vissprites.reserve(::g->vissprites.size() + MAXVISSPRITES);
}
::g->vissprites.emplace_back(new vissprite_t());
#else
if (::g->vissprites.size() == ::g->vissprites.capacity()) {
::g->vissprites.resize(::g->vissprites.size() + MAXVISSPRITES);
}
for (int vi = ::g->visspriteind; vi < ::g->vissprites.size(); vi++) {
::g->vissprites[vi] = new vissprite_t();
}
#endif
}
else {
R_ZeroVisSprite(::g->visspriteind);
Expand Down

0 comments on commit 1cf31f4

Please sign in to comment.