From ae9ae781fce5339c67e8a37b66073e9ad48c47b6 Mon Sep 17 00:00:00 2001 From: VladimirMangos Date: Thu, 22 Oct 2009 06:32:37 +0400 Subject: [PATCH] [8704] Fixed crash "Object with certain key already in but objects are different!" * It possible in result events 1) creature move from respawn grid 2) respawn grid unloaded by timeout, but not current grid for creature 3) respawn grid loaded before current grid with creture unload 4) duplicate attempt created in old grid Until recent guid storage move to map we create duplicate creature with same (continent) or diff guid. With diff strange possible result in it work in world. --- src/game/ObjectGridLoader.cpp | 20 +++++++++++++++++++- src/shared/revision_nr.h | 2 +- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/game/ObjectGridLoader.cpp b/src/game/ObjectGridLoader.cpp index 9c60cd2b1..dff9cd426 100644 --- a/src/game/ObjectGridLoader.cpp +++ b/src/game/ObjectGridLoader.cpp @@ -104,6 +104,16 @@ template<> void addUnitState(Creature *obj, CellPair const& cell_pair) obj->SetCurrentCell(cell); } +template bool alreadyLoaded(Map* /*map*/, uint32 /*guid*/, T* /*fake*/) +{ + // Non creature objects not walk by grids +} + +template<> bool alreadyLoaded(Map* map, uint32 guid, Creature* fake) +{ + return map->GetObjectsStore().find(guid,fake); +} + template void LoadHelper(CellGuidSet const& guid_set, CellPair &cell, GridRefManager &m, uint32 &count, Map* map) { @@ -111,8 +121,16 @@ void LoadHelper(CellGuidSet const& guid_set, CellPair &cell, GridRefManager & for(CellGuidSet::const_iterator i_guid = guid_set.begin(); i_guid != guid_set.end(); ++i_guid) { - T* obj = new T; uint32 guid = *i_guid; + + // Note: this will fully correct work only at non-instanced maps, + // at instanced maps will use dynamic selected guid + // and then duplicate just will not detected and will be 2 creature with identical DB guid + // with some chance + if (alreadyLoaded(map,guid,(T*)NULL)) + continue; // still loaded in another grid (move from respawn [this] grid early), we not need second copy + + T* obj = new T; //sLog.outString("DEBUG: LoadHelper from table: %s for (guid: %u) Loading",table,guid); if(!obj->LoadFromDB(guid, map)) { diff --git a/src/shared/revision_nr.h b/src/shared/revision_nr.h index b36d78094..9ffec8043 100644 --- a/src/shared/revision_nr.h +++ b/src/shared/revision_nr.h @@ -1,4 +1,4 @@ #ifndef __REVISION_NR_H__ #define __REVISION_NR_H__ - #define REVISION_NR "8703" + #define REVISION_NR "8704" #endif // __REVISION_NR_H__