- [FIX] Solventats els problemes de memòria al eliminar un actor

This commit is contained in:
2024-10-09 12:03:16 +02:00
parent ac4e1f3298
commit cabbb52cbb
2 changed files with 32 additions and 3 deletions

View File

@@ -33,6 +33,7 @@ namespace actor
int walk_channel = -1; int walk_channel = -1;
bool push_sound_already_playing = false; bool push_sound_already_playing = false;
std::vector<actor_t*> purgatory;
void resetTag() void resetTag()
{ {
@@ -69,6 +70,7 @@ namespace actor
act->surface = draw::getSurface(bmp.c_str()); act->surface = draw::getSurface(bmp.c_str());
act->bmp_rect = r; act->bmp_rect = r;
act->bmp_offset = o; act->bmp_offset = o;
act->alive = true;
return act; return act;
} }
@@ -89,6 +91,8 @@ namespace actor
act->react_mask = act->react_push = 0; act->react_mask = act->react_push = 0;
act->flags = FLAG_NONE; act->flags = FLAG_NONE;
act->template_category = 0; act->template_category = 0;
act->alive = true;
return act; return act;
} }
@@ -233,7 +237,7 @@ namespace actor
newactor->prev = act->prev; newactor->prev = act->prev;
newactor->next = act->next; newactor->next = act->next;
act->prev = act->next = nullptr; act->prev = act->next = nullptr;
remove(act); sendToPurgatory(act);
return newactor; return newactor;
} }
@@ -1229,7 +1233,7 @@ namespace actor
room::load(room::getExit(XP)); room::load(room::getExit(XP));
if (llevar_abad) if (llevar_abad)
{ {
actor::remove(actor::find("ABAD")); actor::sendToPurgatory(actor::find("ABAD"));
} }
act->pos.x = room::getMin().x - 3; act->pos.x = room::getMin().x - 3;
act->pos.z = room::getDoor(XN) * 4; act->pos.z = room::getDoor(XN) * 4;
@@ -1427,7 +1431,7 @@ namespace actor
{ {
if (act->name[0] == '_') if (act->name[0] == '_')
{ {
actor::remove(act); actor::sendToPurgatory(act);
return; return;
} }
else else
@@ -1672,6 +1676,26 @@ namespace actor
free(act); free(act);
} }
void sendToPurgatory(actor_t *act)
{
if (!act) return;
if (act->prev) act->prev->next = act->next;
if (act == first) first = act->next;
if (act == dirty) dirty = act->next;
if (act->next) act->next->prev = act->prev;
if (act == selected) selected = nullptr;
if (act->below) act->below->above = nullptr;
if (act->above) act->above->below = nullptr;
act->alive = false;
purgatory.push_back(act);
}
void cleanPurgatory()
{
for (auto act : purgatory) remove(act);
purgatory.clear();
}
void pick(actor_t *act) void pick(actor_t *act)
{ {
if (!act) if (!act)

View File

@@ -109,6 +109,7 @@ namespace actor
int tag; int tag;
int template_category; int template_category;
bool alive;
}; };
void resetTag(); void resetTag();
@@ -169,6 +170,10 @@ namespace actor
void remove(actor_t *act); void remove(actor_t *act);
void sendToPurgatory(actor_t *act);
void cleanPurgatory();
void pick(actor_t *act); void pick(actor_t *act);
actor_t *getPicked(); actor_t *getPicked();