[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.
This commit is contained in:
VladimirMangos 2009-10-22 06:32:37 +04:00
parent f762b57fea
commit ae9ae781fc
2 changed files with 20 additions and 2 deletions

View file

@ -104,6 +104,16 @@ template<> void addUnitState(Creature *obj, CellPair const& cell_pair)
obj->SetCurrentCell(cell);
}
template<class T> 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<Creature>(guid,fake);
}
template <class T>
void LoadHelper(CellGuidSet const& guid_set, CellPair &cell, GridRefManager<T> &m, uint32 &count, Map* map)
{
@ -111,8 +121,16 @@ void LoadHelper(CellGuidSet const& guid_set, CellPair &cell, GridRefManager<T> &
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))
{

View file

@ -1,4 +1,4 @@
#ifndef __REVISION_NR_H__
#define __REVISION_NR_H__
#define REVISION_NR "8703"
#define REVISION_NR "8704"
#endif // __REVISION_NR_H__