Skip to content

Commit

Permalink
Switch Eluna objects from raw pointers to unique pointers
Browse files Browse the repository at this point in the history
  • Loading branch information
Foereaper committed Feb 24, 2025
1 parent 6499eda commit 838a277
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 18 deletions.
9 changes: 2 additions & 7 deletions src/server/game/Maps/Map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,6 @@ struct RespawnInfoWithHandle : RespawnInfo

Map::~Map()
{
#ifdef ELUNA
delete eluna;
eluna = nullptr;
#endif

// Delete all waiting spawns, else there will be a memory leak
// This doesn't delete from database.
UnloadAllRespawnInfos();
Expand Down Expand Up @@ -296,7 +291,7 @@ i_scriptLock(false), _respawnTimes(std::make_unique<RespawnListContainer>()), _r

if (sElunaConfig->IsElunaEnabled() && !sElunaConfig->IsElunaCompatibilityMode() && sElunaConfig->ShouldMapLoadEluna(id))
if (!IsParentMap() || (IsParentMap() && !Instanceable()))
eluna = new Eluna(this);
eluna = std::make_unique<Eluna>(this);
#endif
for (unsigned int idx=0; idx < MAX_NUMBER_OF_GRIDS; ++idx)
{
Expand Down Expand Up @@ -4902,7 +4897,7 @@ Eluna *Map::GetEluna() const
if(sElunaConfig->IsElunaCompatibilityMode())
return sWorld->GetEluna();

return eluna;
return eluna.get();
}
#endif

Expand Down
2 changes: 1 addition & 1 deletion src/server/game/Maps/Map.h
Original file line number Diff line number Diff line change
Expand Up @@ -872,7 +872,7 @@ class TC_GAME_API Map : public GridRefManager<NGridType>

MPSCQueue<FarSpellCallback> _farSpellCallbacks;
#ifdef ELUNA
Eluna* eluna;
std::unique_ptr<Eluna> eluna;
#endif
};

Expand Down
8 changes: 1 addition & 7 deletions src/server/game/World/World.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,12 +155,6 @@ World::World()
/// World destructor
World::~World()
{
#ifdef ELUNA
// Delete world Eluna state
delete eluna;
eluna = nullptr;
#endif

///- Empty the kicked session set
while (!m_sessions.empty())
{
Expand Down Expand Up @@ -2125,7 +2119,7 @@ void World::SetInitialWorldSettings()
if (sElunaConfig->IsElunaEnabled())
{
TC_LOG_INFO("server.loading", "Starting Eluna world state...");
eluna = new Eluna(nullptr, sElunaConfig->IsElunaCompatibilityMode());
eluna = std::make_unique<Eluna>(nullptr, sElunaConfig->IsElunaCompatibilityMode());
}
#endif

Expand Down
4 changes: 2 additions & 2 deletions src/server/game/World/World.h
Original file line number Diff line number Diff line change
Expand Up @@ -774,8 +774,8 @@ class TC_GAME_API World
bool IsGuidAlert() { return _guidAlert; }

#ifdef ELUNA
Eluna* GetEluna() const { return eluna; }
Eluna* eluna;
Eluna* GetEluna() const { return eluna.get(); }
std::unique_ptr<Eluna> eluna;
#endif
protected:
void _UpdateGameTime();
Expand Down

0 comments on commit 838a277

Please sign in to comment.