From bcee010ef3d11744fea7d25711a9582af611e79b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=A9=E9=B9=AD?= <18535853+PkllonG@users.noreply.github.com> Date: Sat, 4 Oct 2025 22:36:56 +0800 Subject: [PATCH 1/7] Update EventProcessor.h --- src/common/Utilities/EventProcessor.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/common/Utilities/EventProcessor.h b/src/common/Utilities/EventProcessor.h index 3e7896bb33..08cc5e8c54 100644 --- a/src/common/Utilities/EventProcessor.h +++ b/src/common/Utilities/EventProcessor.h @@ -122,6 +122,8 @@ class EventProcessor void CancelEventGroup(uint8 group); + bool HaveEventList() const { return !m_events.empty(); } + protected: uint64 m_time{0}; EventList m_events; From eb05f05b48b5fc6075f770ee886459226733ed75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=A9=E9=B9=AD?= <18535853+PkllonG@users.noreply.github.com> Date: Sat, 4 Oct 2025 22:37:49 +0800 Subject: [PATCH 2/7] Update Map.h --- src/server/game/Maps/Map.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/server/game/Maps/Map.h b/src/server/game/Maps/Map.h index 20551da8a0..e9f6a8da1a 100644 --- a/src/server/game/Maps/Map.h +++ b/src/server/game/Maps/Map.h @@ -23,6 +23,7 @@ #include "DataMap.h" #include "Define.h" #include "DynamicTree.h" +#include "EventProcessor.h" #include "GameObjectModel.h" #include "GridDefines.h" #include "GridRefMgr.h" @@ -33,7 +34,6 @@ #include "PathGenerator.h" #include "Position.h" #include "SharedDefines.h" -#include "TaskScheduler.h" #include "Timer.h" #include "GridTerrainData.h" #include @@ -172,7 +172,7 @@ public: // currently unused for normal maps bool CanUnload(uint32 diff) { - if (!m_unloadTimer) + if (!m_unloadTimer || m_Events.HaveEventList()) return false; if (m_unloadTimer <= diff) @@ -430,7 +430,7 @@ public: void UpdatePlayerZoneStats(uint32 oldZone, uint32 newZone); [[nodiscard]] uint32 ApplyDynamicModeRespawnScaling(WorldObject const* obj, uint32 respawnDelay) const; - TaskScheduler _creatureRespawnScheduler; + EventProcessor m_Events; void ScheduleCreatureRespawn(ObjectGuid /*creatureGuid*/, Milliseconds /*respawnTimer*/, Position pos = Position()); From 131613c770326edf6002a9e81d53acf83669f162 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=A9=E9=B9=AD?= <18535853+PkllonG@users.noreply.github.com> Date: Sat, 4 Oct 2025 22:38:41 +0800 Subject: [PATCH 3/7] Update Map.cpp --- src/server/game/Maps/Map.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/server/game/Maps/Map.cpp b/src/server/game/Maps/Map.cpp index de0e4a9bd6..6d55edf690 100644 --- a/src/server/game/Maps/Map.cpp +++ b/src/server/game/Maps/Map.cpp @@ -54,6 +54,8 @@ Map::~Map() { // UnloadAll must be called before deleting the map + m_Events.KillAllEvents(true); + sScriptMgr->OnDestroyMap(this); if (!m_scriptSchedule.empty()) @@ -447,7 +449,7 @@ void Map::Update(const uint32 t_diff, const uint32 s_diff, bool /*thread*/) } } - _creatureRespawnScheduler.Update(t_diff); + m_Events.Update(t_diff); if (!t_diff) { @@ -2760,13 +2762,13 @@ void Map::RemoveOldCorpses() void Map::ScheduleCreatureRespawn(ObjectGuid creatureGuid, Milliseconds respawnTimer, Position pos) { - _creatureRespawnScheduler.Schedule(respawnTimer, [this, creatureGuid, pos](TaskContext) + m_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) From d931498c70ba90313e43ae4997162f55b6165223 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=A9=E9=B9=AD?= <18535853+PkllonG@users.noreply.github.com> Date: Sun, 5 Oct 2025 00:37:40 +0800 Subject: [PATCH 4/7] Update Map.cpp --- src/server/game/Maps/Map.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/server/game/Maps/Map.cpp b/src/server/game/Maps/Map.cpp index 6d55edf690..57fee2419a 100644 --- a/src/server/game/Maps/Map.cpp +++ b/src/server/game/Maps/Map.cpp @@ -54,7 +54,7 @@ Map::~Map() { // UnloadAll must be called before deleting the map - m_Events.KillAllEvents(true); + m_Events.KillAllEvents(false); sScriptMgr->OnDestroyMap(this); From 052d8b1cae5d15d3ce4ba9cc1f46d449fc46a4f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=A9=E9=B9=AD?= <18535853+PkllonG@users.noreply.github.com> Date: Sat, 11 Oct 2025 16:04:45 +0800 Subject: [PATCH 5/7] Update src/server/game/Maps/Map.cpp Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- src/server/game/Maps/Map.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/server/game/Maps/Map.cpp b/src/server/game/Maps/Map.cpp index 57fee2419a..204c208b18 100644 --- a/src/server/game/Maps/Map.cpp +++ b/src/server/game/Maps/Map.cpp @@ -54,6 +54,8 @@ 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. m_Events.KillAllEvents(false); sScriptMgr->OnDestroyMap(this); From 12c56e2a3b2e93ad5c115c7eb27636f07df73da9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=A9=E9=B9=AD?= <18535853+PkllonG@users.noreply.github.com> Date: Fri, 17 Oct 2025 13:15:59 +0800 Subject: [PATCH 6/7] m_Events to Events --- src/common/Utilities/EventProcessor.h | 1 - src/server/game/Maps/Map.cpp | 6 +++--- src/server/game/Maps/Map.h | 4 ++-- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/common/Utilities/EventProcessor.h b/src/common/Utilities/EventProcessor.h index 08cc5e8c54..3ed45a50ca 100644 --- a/src/common/Utilities/EventProcessor.h +++ b/src/common/Utilities/EventProcessor.h @@ -121,7 +121,6 @@ class EventProcessor [[nodiscard]] uint64 CalculateQueueTime(uint64 delay) const; void CancelEventGroup(uint8 group); - bool HaveEventList() const { return !m_events.empty(); } protected: diff --git a/src/server/game/Maps/Map.cpp b/src/server/game/Maps/Map.cpp index 180a5eac73..092b008d3b 100644 --- a/src/server/game/Maps/Map.cpp +++ b/src/server/game/Maps/Map.cpp @@ -56,7 +56,7 @@ Map::~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. - m_Events.KillAllEvents(false); + Events.KillAllEvents(false); sScriptMgr->OnDestroyMap(this); @@ -451,7 +451,7 @@ void Map::Update(const uint32 t_diff, const uint32 s_diff, bool /*thread*/) } } - m_Events.Update(t_diff); + Events.Update(t_diff); if (!t_diff) { @@ -2762,7 +2762,7 @@ void Map::RemoveOldCorpses() void Map::ScheduleCreatureRespawn(ObjectGuid creatureGuid, Milliseconds respawnTimer, Position pos) { - m_Events.AddEventAtOffset([this, creatureGuid, pos]() + Events.AddEventAtOffset([this, creatureGuid, pos]() { if (Creature* creature = GetCreature(creatureGuid)) creature->Respawn(); diff --git a/src/server/game/Maps/Map.h b/src/server/game/Maps/Map.h index f60261af72..d5c577fd10 100644 --- a/src/server/game/Maps/Map.h +++ b/src/server/game/Maps/Map.h @@ -172,7 +172,7 @@ public: // currently unused for normal maps bool CanUnload(uint32 diff) { - if (!m_unloadTimer || m_Events.HaveEventList()) + if (!m_unloadTimer || Events.HaveEventList()) return false; if (m_unloadTimer <= diff) @@ -430,7 +430,7 @@ public: void UpdatePlayerZoneStats(uint32 oldZone, uint32 newZone); [[nodiscard]] uint32 ApplyDynamicModeRespawnScaling(WorldObject const* obj, uint32 respawnDelay) const; - EventProcessor m_Events; + EventProcessor Events; void ScheduleCreatureRespawn(ObjectGuid /*creatureGuid*/, Milliseconds /*respawnTimer*/, Position pos = Position()); From 832b3091f0cf99e34ed355fbf95339ba8842e786 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=A9=E9=B9=AD?= <18535853+PkllonG@users.noreply.github.com> Date: Fri, 17 Oct 2025 13:55:29 +0800 Subject: [PATCH 7/7] HasEvents --- src/common/Utilities/EventProcessor.h | 2 +- src/server/game/Maps/Map.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/common/Utilities/EventProcessor.h b/src/common/Utilities/EventProcessor.h index 3ed45a50ca..1dcbcf8208 100644 --- a/src/common/Utilities/EventProcessor.h +++ b/src/common/Utilities/EventProcessor.h @@ -121,7 +121,7 @@ class EventProcessor [[nodiscard]] uint64 CalculateQueueTime(uint64 delay) const; void CancelEventGroup(uint8 group); - bool HaveEventList() const { return !m_events.empty(); } + bool HasEvents() const { return !m_events.empty(); } protected: uint64 m_time{0}; diff --git a/src/server/game/Maps/Map.h b/src/server/game/Maps/Map.h index d5c577fd10..eaac429624 100644 --- a/src/server/game/Maps/Map.h +++ b/src/server/game/Maps/Map.h @@ -172,7 +172,7 @@ public: // currently unused for normal maps bool CanUnload(uint32 diff) { - if (!m_unloadTimer || Events.HaveEventList()) + if (!m_unloadTimer || Events.HasEvents()) return false; if (m_unloadTimer <= diff)