generated from sigonasr2/CPlusPlusProjectTemplate
Fix object memory clearing error
Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
This commit is contained in:
parent
d700d8b83c
commit
b5dfa1e7de
@ -451,7 +451,7 @@ public:
|
|||||||
std::string MAP_NAME = "";
|
std::string MAP_NAME = "";
|
||||||
std::string CUTSCENE_CONSOLE_TEXT = "";
|
std::string CUTSCENE_CONSOLE_TEXT = "";
|
||||||
bool GAME_FLAGS[128]={};
|
bool GAME_FLAGS[128]={};
|
||||||
int**MAP=(int**)malloc(sizeof(int**)*0);
|
int**MAP=NULL;
|
||||||
int MAP_WIDTH=-1;
|
int MAP_WIDTH=-1;
|
||||||
int MAP_HEIGHT=-1;
|
int MAP_HEIGHT=-1;
|
||||||
Decal*TILES;
|
Decal*TILES;
|
||||||
@ -2540,7 +2540,7 @@ public:
|
|||||||
StartCutscene(cutscene::CHECK_COORDS_2);
|
StartCutscene(cutscene::CHECK_COORDS_2);
|
||||||
CUTSCENE_OBJS[0]=CreateObject({PLAYER_COORDS[0],PLAYER_COORDS[1]},PLAYER_DECAL,playerAnim,true);
|
CUTSCENE_OBJS[0]=CreateObject({PLAYER_COORDS[0],PLAYER_COORDS[1]},PLAYER_DECAL,playerAnim,true);
|
||||||
}
|
}
|
||||||
if(WALK_STEPS++>60&&!IN_BATTLE_ENCOUNTER&&playerCanMove()) {
|
if(WALK_STEPS++>60&&!IN_BATTLE_ENCOUNTER) {
|
||||||
PLAYER_HP=std::clamp(PLAYER_HP+1,0,PLAYER_MAXHP);
|
PLAYER_HP=std::clamp(PLAYER_HP+1,0,PLAYER_MAXHP);
|
||||||
updatePlayerState();
|
updatePlayerState();
|
||||||
WALK_STEPS=0;
|
WALK_STEPS=0;
|
||||||
@ -2893,12 +2893,14 @@ public:
|
|||||||
std::ifstream f("assets/maps/"+map->filename);
|
std::ifstream f("assets/maps/"+map->filename);
|
||||||
std::string data;
|
std::string data;
|
||||||
CURRENT_MAP=map;
|
CURRENT_MAP=map;
|
||||||
if (MAP!=nullptr) {
|
MAP_WIDTH=MAP_HEIGHT=-1;
|
||||||
|
if (MAP!=NULL) {
|
||||||
for (int y=0;y<MAP_HEIGHT;y++) {
|
for (int y=0;y<MAP_HEIGHT;y++) {
|
||||||
free(MAP[y]);
|
free(MAP[y]);
|
||||||
}
|
}
|
||||||
|
free(MAP);
|
||||||
|
MAP=NULL;
|
||||||
}
|
}
|
||||||
MAP_WIDTH=MAP_HEIGHT=-1;
|
|
||||||
for (int i=0;i<OBJECTS.size();i++) {
|
for (int i=0;i<OBJECTS.size();i++) {
|
||||||
delete OBJECTS[i];
|
delete OBJECTS[i];
|
||||||
}
|
}
|
||||||
@ -2917,7 +2919,9 @@ public:
|
|||||||
stream>>MAP_HEIGHT;
|
stream>>MAP_HEIGHT;
|
||||||
} else
|
} else
|
||||||
if (y<MAP_HEIGHT) {
|
if (y<MAP_HEIGHT) {
|
||||||
MAP=(int**)realloc(MAP,sizeof(int**)*MAP_HEIGHT);
|
if (MAP==NULL) {
|
||||||
|
MAP=(int**)malloc(sizeof(int**)*MAP_HEIGHT);
|
||||||
|
}
|
||||||
MAP[y]=(int*)malloc(sizeof(int*)*MAP_WIDTH);
|
MAP[y]=(int*)malloc(sizeof(int*)*MAP_WIDTH);
|
||||||
for (int i=0;i<data.length();i++) {
|
for (int i=0;i<data.length();i++) {
|
||||||
MAP[y][i]=data[i]-'0';
|
MAP[y][i]=data[i]-'0';
|
||||||
@ -3345,10 +3349,10 @@ public:
|
|||||||
for (int j=0;j<OBJECTS.size();j++) {
|
for (int j=0;j<OBJECTS.size();j++) {
|
||||||
if (OBJECTS[j]==CUTSCENE_OBJS[i]) {
|
if (OBJECTS[j]==CUTSCENE_OBJS[i]) {
|
||||||
if (CUTSCENE_OBJS[i]->tempObj) {
|
if (CUTSCENE_OBJS[i]->tempObj) {
|
||||||
OBJECTS.erase(OBJECTS.begin()+j);
|
OBJECTS.erase(OBJECTS.begin()+j--);
|
||||||
std::cout<<"Erased at position "<<j<<".\n";
|
std::cout<<"Erased at position "<<j<<".\n";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
delete CUTSCENE_OBJS[i];
|
delete CUTSCENE_OBJS[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user