From a6300b5c3bbd0c28005fe984e59edf8a034c1943 Mon Sep 17 00:00:00 2001 From: Niam5 Date: Mon, 15 Jul 2024 21:07:03 -0700 Subject: [PATCH] Fix elunaEvent init and de-init Fixes multiple crashes related to BG's Co-Authored-By: Foe --- src/game/Entities/Object.cpp | 32 ++++++++++++-------------------- 1 file changed, 12 insertions(+), 20 deletions(-) diff --git a/src/game/Entities/Object.cpp b/src/game/Entities/Object.cpp index b649295380a..8820f8d172d 100644 --- a/src/game/Entities/Object.cpp +++ b/src/game/Entities/Object.cpp @@ -1242,7 +1242,7 @@ bool WorldObject::HasStringId(uint32 stringId) const WorldObject::WorldObject() : #ifdef BUILD_ELUNA - elunaEvents(NULL), + elunaEvents(nullptr), #endif m_transport(nullptr), m_transportInfo(nullptr), m_isOnEventNotified(false), m_visibilityData(this), m_currMap(nullptr), @@ -1255,7 +1255,7 @@ WorldObject::WorldObject() : WorldObject::~WorldObject() { delete elunaEvents; - elunaEvents = NULL; + elunaEvents = nullptr; } #endif @@ -2058,24 +2058,6 @@ void WorldObject::SetMap(Map* map) // lets save current map's Id/instanceId m_mapId = map->GetId(); m_InstanceId = map->GetInstanceId(); -#ifdef BUILD_ELUNA - //@todo: possibly look into cleanly clearing all pending events from previous map's event mgr. - - // if multistate, delete elunaEvents and set to nullptr. events shouldn't move across states. - // in single state, the timed events should move across maps - if (!sElunaConfig->IsElunaCompatibilityMode()) - { - if (elunaEvents) - { - delete elunaEvents; - elunaEvents = nullptr; // set to null in case map doesn't use eluna - } - } - - if (Eluna* e = map->GetEluna()) - if (!elunaEvents) - elunaEvents = new ElunaEventProcessor(e, this); -#endif } void WorldObject::AddToWorld() @@ -2102,6 +2084,16 @@ void WorldObject::RemoveFromWorld() m_currMap->RemoveStringIdObject(stringId, this); } +#ifdef BUILD_ELUNA + // if multistate, delete elunaEvents and set to nullptr. events shouldn't move across states. + // in single state, the timed events should move across maps + if (!sElunaConfig->IsElunaCompatibilityMode()) + { + delete elunaEvents; + elunaEvents = nullptr; // set to null in case map doesn't use eluna + } +#endif + Object::RemoveFromWorld(); }