diff --git a/src/server/game/Entities/Unit/Unit.cpp b/src/server/game/Entities/Unit/Unit.cpp index e75a49358..0d3ed374b 100644 --- a/src/server/game/Entities/Unit/Unit.cpp +++ b/src/server/game/Entities/Unit/Unit.cpp @@ -15971,6 +15971,13 @@ void Unit::CleanupBeforeRemoveFromMap(bool finalCleanup) if (IsInWorld()) // not in world and not being removed atm RemoveFromWorld(); + // added for mod_playerbots crash fixes; m_Events.KillAllEvents(false) placed after RemoveFromWorld and + // interupt and before RemoveAllAuras. + // Cancel and remove pending events (including SpellEvent) before aura/spellmod cleanup. + // Without this, SpellEvent may be cancelled later during EventProcessor destruction after auras/spellmods are gone, + // leading to invalid access in Player::RestoreSpellMods on logout. + m_Events.KillAllEvents(false); + ASSERT(GetGUID()); // A unit may be in removelist and not in world, but it is still in grid