Skip to content

Instantly share code, notes, and snippets.

@rsa
Created September 3, 2011 19:52
Show Gist options
  • Select an option

  • Save rsa/1191680 to your computer and use it in GitHub Desktop.

Select an option

Save rsa/1191680 to your computer and use it in GitHub Desktop.
diff --git a/src/game/Map.cpp b/src/game/Map.cpp
index 6a17fbc..eaa9e8c 100644
--- a/src/game/Map.cpp
+++ b/src/game/Map.cpp
@@ -195,6 +195,9 @@ void Map::RemoveFromGrid(Creature* obj, NGridType *grid, Cell const& cell)
void Map::DeleteFromWorld(Player* pl)
{
sObjectAccessor.RemoveObject(pl);
+
+ WriteGuard Guard(GetLock(MAP_LOCK_TYPE_AURAS));
+
delete pl;
}
@@ -654,7 +657,6 @@ Map::Remove(T *obj, bool remove)
if (obj->GetTypeId() == TYPEID_UNIT)
RemoveAttackersStorageFor(obj->GetObjectGuid());
- obj->ResetMap();
if( remove )
{
// if option set then object already saved at this moment
@@ -662,6 +664,7 @@ Map::Remove(T *obj, bool remove)
obj->SaveRespawnTime();
// Note: In case resurrectable corpse and pet its removed from global lists in own destructor
+ WriteGuard Guard(GetLock(MAP_LOCK_TYPE_AURAS));
delete obj;
}
}
diff --git a/src/game/Map.h b/src/game/Map.h
index 11cc9b3..1fc73a1 100644
--- a/src/game/Map.h
+++ b/src/game/Map.h
@@ -126,7 +126,7 @@ class MANGOS_DLL_SPEC Map : public GridRefManager<NGridType>
template<class T> void Add(T *);
template<class T> void Remove(T *, bool);
- static void DeleteFromWorld(Player* player); // player object will deleted at call
+ void DeleteFromWorld(Player* player); // player object will deleted at call
virtual void Update(const uint32&);
diff --git a/src/game/Pet.cpp b/src/game/Pet.cpp
index ff0a127..13c2542 100644
--- a/src/game/Pet.cpp
+++ b/src/game/Pet.cpp
@@ -56,6 +56,8 @@ m_petFollowAngle(PET_FOLLOW_ANGLE), m_needSave(true), m_petCounter(0), m_PetScal
Pet::~Pet()
{
+ CleanupsBeforeDelete();
+
delete m_declinedname;
if (m_PetScalingData)
diff --git a/src/game/Unit.cpp b/src/game/Unit.cpp
index 50adeb4..1317c13 100644
--- a/src/game/Unit.cpp
+++ b/src/game/Unit.cpp
@@ -308,10 +308,10 @@ Unit::~Unit()
}
}
- delete m_charmInfo;
- delete m_vehicleInfo;
CleanupDeletedAuras();
+ delete m_charmInfo;
+ delete m_vehicleInfo;
delete movespline;
// those should be already removed at "RemoveFromWorld()" call
@@ -10198,7 +10198,7 @@ void Unit::RemoveFromWorld()
UnsummonAllTotems();
RemoveAllGameObjects();
RemoveAllDynObjects();
- CleanupDeletedAuras();
+// CleanupDeletedAuras();
GetViewPoint().Event_RemovedFromWorld();
}
diff --git a/src/game/WorldSession.cpp b/src/game/WorldSession.cpp
index 02a65bc..37daf95 100644
--- a/src/game/WorldSession.cpp
+++ b/src/game/WorldSession.cpp
@@ -556,7 +556,13 @@ void WorldSession::LogoutPlayer(bool Save)
else
{
GetPlayer()->CleanupsBeforeDelete();
- Map::DeleteFromWorld(GetPlayer());
+ if (GetPlayer()->GetMap())
+ GetPlayer()->GetMap()->DeleteFromWorld(GetPlayer());
+ else
+ {
+ sObjectAccessor.RemoveObject(GetPlayer());
+ delete GetPlayer();
+ }
}
SetPlayer(NULL); // deleted in Remove/DeleteFromWorld call
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment