Skip to content

Commit

Permalink
Fix memory leak when spawning dragons
Browse files Browse the repository at this point in the history
  • Loading branch information
IonAgorria committed Jun 10, 2024
1 parent 18017d4 commit 4c868ea
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
8 changes: 7 additions & 1 deletion Source/Terra/geo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1515,7 +1515,6 @@ loc_notOverlapped: ;
int elementGeoBreak::unengagedID=0; //Инициализация уникального ида элемента трещины для поиска родителей при завершении

geoBreak1::geoBreak1(int x, int y, int rad, int beginNumBreaks){ //0-случайное кол-во
elGB.erase(elGB.begin(), elGB.end());//очистка списка элементов трещин
if(beginNumBreaks==0) beginNumBreaks=2+terLogicRND(MAX_BEGIN_BREAKS-2);//Диапазон от 2 до MAX_BEGIN_BREAKS

float range_corner=2*pi/((float)beginNumBreaks);
Expand All @@ -1530,6 +1529,13 @@ geoBreak1::geoBreak1(int x, int y, int rad, int beginNumBreaks){ //0-случа
}
};

geoBreak1::~geoBreak1() {
for (auto el : elGB) {
delete el;
}
elGB.clear();
}

std::list<elementGeoBreak*>::iterator geoBreak1::delEementGeoBreak(std::list<elementGeoBreak*>::iterator pp)
{
int _ownID=(*pp)->ownerID;
Expand Down
5 changes: 3 additions & 2 deletions Source/Terra/geo.h
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,7 @@ const float CORNER_DISPERSION_BREAKS=(float)(pi+pi/2);
struct geoBreak1{ //точечный разлом
std::list<elementGeoBreak*> elGB;
geoBreak1(int x, int y, int rad=MAX_LENGHT_ELEMENTGEOBREAK, int beginNumBreaks=0); //0-случайное кол-во
~geoBreak1();
std::list<elementGeoBreak*>::iterator delEementGeoBreak(std::list<elementGeoBreak*>::iterator pp);
int quant(void);
};
Expand Down Expand Up @@ -1160,15 +1161,15 @@ struct s_WaspBirthGeoAction {
radiusCount=0;
};
~s_WaspBirthGeoAction(){
if(pGeoBrk1) delete pGeoBrk1;
delete pGeoBrk1;
}
bool quant(void){
quantCount++;

if((radiusCount<r) && (pGeoBrk1)) {
if(pGeoBrk1->quant()==0){
delete pGeoBrk1;
pGeoBrk1=0;
pGeoBrk1= nullptr;
}
}
if(quantCount>=WASP_SHIFT_QUANT_FOR_GEOBREAK){
Expand Down

0 comments on commit 4c868ea

Please sign in to comment.