Skip to content

Commit

Permalink
Fix elunaEvent init and de-init
Browse files Browse the repository at this point in the history
Fixes multiple crashes related to BG's

Co-Authored-By: Foe <Foereaper@users.noreply.github.com>
  • Loading branch information
Niam5 and Foereaper committed Jul 27, 2024
1 parent e79e0f1 commit a6300b5
Showing 1 changed file with 12 additions and 20 deletions.
32 changes: 12 additions & 20 deletions src/game/Entities/Object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -1255,7 +1255,7 @@ WorldObject::WorldObject() :
WorldObject::~WorldObject()
{
delete elunaEvents;
elunaEvents = NULL;
elunaEvents = nullptr;
}
#endif

Expand Down Expand Up @@ -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()
Expand All @@ -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();
}

Expand Down

0 comments on commit a6300b5

Please sign in to comment.