fix(Core/Map): It should be ensured that the instance is unloaded only after the Creature Respawn. (#23103)

This commit is contained in:
天鹭
2025-11-11 13:59:57 +08:00
committed by GitHub
parent 3fda02939b
commit 8f5d50435b
3 changed files with 11 additions and 7 deletions

View File

@@ -54,6 +54,10 @@ Map::~Map()
{
// UnloadAll must be called before deleting the map
// Kill all scheduled events without executing them, since the map and its objects are being destroyed.
// This prevents events from running on invalid or deleted objects during map destruction.
Events.KillAllEvents(false);
sScriptMgr->OnDestroyMap(this);
if (!m_scriptSchedule.empty())
@@ -447,7 +451,7 @@ void Map::Update(const uint32 t_diff, const uint32 s_diff, bool /*thread*/)
}
}
_creatureRespawnScheduler.Update(t_diff);
Events.Update(t_diff);
if (!t_diff)
{
@@ -2747,13 +2751,13 @@ void Map::RemoveOldCorpses()
void Map::ScheduleCreatureRespawn(ObjectGuid creatureGuid, Milliseconds respawnTimer, Position pos)
{
_creatureRespawnScheduler.Schedule(respawnTimer, [this, creatureGuid, pos](TaskContext)
Events.AddEventAtOffset([this, creatureGuid, pos]()
{
if (Creature* creature = GetCreature(creatureGuid))
creature->Respawn();
else
SummonCreature(creatureGuid.GetEntry(), pos);
});
}, respawnTimer);
}
/// Send a packet to all players (or players selected team) in the zone (except self if mentioned)