Fix the crash when removing object from an unloaded grid. Object should always be unlinked from grid no matter if the grid is loaded.

This commit is contained in:
megamage
2011-11-10 17:31:45 -05:00
parent 23b3f16f3a
commit 31a88d4fe5
6 changed files with 51 additions and 95 deletions
+14 -16
View File
@@ -58,20 +58,19 @@ class Grid
*/
template<class SPECIFIC_OBJECT> void AddWorldObject(SPECIFIC_OBJECT *obj)
{
ASSERT(!obj->GetGridRef().isValid());
i_objects.template insert<SPECIFIC_OBJECT>(obj);
ASSERT(obj->GetGridRef().isValid());
ASSERT(obj->IsInGrid());
}
/** an object of interested exits the grid
*/
//Actually an unlink is enough, no need to go through the container
template<class SPECIFIC_OBJECT> void RemoveWorldObject(SPECIFIC_OBJECT *obj)
{
ASSERT(obj->GetGridRef().isValid());
i_objects.template remove<SPECIFIC_OBJECT>(obj);
ASSERT(!obj->GetGridRef().isValid());
}
//template<class SPECIFIC_OBJECT> void RemoveWorldObject(SPECIFIC_OBJECT *obj)
//{
// ASSERT(obj->GetGridRef().isValid());
// i_objects.template remove<SPECIFIC_OBJECT>(obj);
// ASSERT(!obj->GetGridRef().isValid());
//}
/** Refreshes/update the grid. This required for remote grids.
*/
@@ -107,19 +106,18 @@ class Grid
*/
template<class SPECIFIC_OBJECT> void AddGridObject(SPECIFIC_OBJECT *obj)
{
ASSERT(!obj->GetGridRef().isValid());
i_container.template insert<SPECIFIC_OBJECT>(obj);
ASSERT(obj->GetGridRef().isValid());
ASSERT(obj->IsInGrid());
}
/** Removes a containter type object from the grid
*/
template<class SPECIFIC_OBJECT> void RemoveGridObject(SPECIFIC_OBJECT *obj)
{
ASSERT(obj->GetGridRef().isValid());
i_container.template remove<SPECIFIC_OBJECT>(obj);
ASSERT(!obj->GetGridRef().isValid());
}
//template<class SPECIFIC_OBJECT> void RemoveGridObject(SPECIFIC_OBJECT *obj)
//{
// ASSERT(obj->GetGridRef().isValid());
// i_container.template remove<SPECIFIC_OBJECT>(obj);
// ASSERT(!obj->GetGridRef().isValid());
//}
/*bool NoWorldObjectInGrid() const
{
+1 -1
View File
@@ -77,7 +77,7 @@ template<> void ObjectGridLoader::SetObjectCell(Creature* obj, CellCoord const&
template <class T>
void AddObjectHelper(CellCoord &cell, GridRefManager<T> &m, uint32 &count, Map* map, T *obj)
{
obj->GetGridRef().link(&m, obj);
obj->AddToGrid(m);
ObjectGridLoader::SetObjectCell(obj, cell);
obj->AddToWorld();
if (obj->isActiveObject())