diff options
author | Shauren <shauren.trinity@gmail.com> | 2023-10-17 15:48:02 +0200 |
---|---|---|
committer | Shauren <shauren.trinity@gmail.com> | 2023-10-17 15:57:03 +0200 |
commit | 966936b01ab732c84832be93fb136da63112cc75 (patch) | |
tree | 13774c92d604ac231f2ebbb2d718af967d145acd | |
parent | d028bb0e374acfc635b2f6f224f5732d3bfa13fd (diff) |
Core/Misc: Fixed thread-unsafe access to list of objects that should be spawned in a cell
Closes #29372
(cherry picked from commit 7b6589c1ecc159f6949c5535785fba79a04b2c4a)
-rw-r--r-- | src/server/game/Entities/Transport/Transport.cpp | 31 | ||||
-rw-r--r-- | src/server/game/Globals/ObjectMgr.cpp | 13 | ||||
-rw-r--r-- | src/server/game/Globals/ObjectMgr.h | 10 | ||||
-rw-r--r-- | src/server/game/Grids/ObjectGridLoader.cpp | 8 |
4 files changed, 35 insertions, 27 deletions
diff --git a/src/server/game/Entities/Transport/Transport.cpp b/src/server/game/Entities/Transport/Transport.cpp index ee309c908de..53f0157f7b2 100644 --- a/src/server/game/Entities/Transport/Transport.cpp +++ b/src/server/game/Entities/Transport/Transport.cpp @@ -532,22 +532,23 @@ void Transport::UpdatePosition(float x, float y, float z, float o) void Transport::LoadStaticPassengers() { - if (uint32 mapId = GetGOInfo()->moTransport.mapID) + uint32 mapId = GetGOInfo()->moTransport.mapID; + if (!mapId) + return; + + CellObjectGuidsMap const* cells = sObjectMgr->GetMapObjectGuids(mapId, GetMap()->GetSpawnMode()); + if (!cells) + return; + + for (auto const& [cellId, guids] : *cells) { - CellObjectGuidsMap const& cells = sObjectMgr->GetMapObjectGuids(mapId, GetMap()->GetSpawnMode()); - CellGuidSet::const_iterator guidEnd; - for (CellObjectGuidsMap::const_iterator cellItr = cells.begin(); cellItr != cells.end(); ++cellItr) - { - // Creatures on transport - guidEnd = cellItr->second.creatures.end(); - for (CellGuidSet::const_iterator guidItr = cellItr->second.creatures.begin(); guidItr != guidEnd; ++guidItr) - CreateNPCPassenger(*guidItr, sObjectMgr->GetCreatureData(*guidItr)); - - // GameObjects on transport - guidEnd = cellItr->second.gameobjects.end(); - for (CellGuidSet::const_iterator guidItr = cellItr->second.gameobjects.begin(); guidItr != guidEnd; ++guidItr) - CreateGOPassenger(*guidItr, sObjectMgr->GetGameObjectData(*guidItr)); - } + // GameObjects on transport + for (ObjectGuid::LowType spawnId : guids.gameobjects) + CreateGOPassenger(spawnId, sObjectMgr->GetGameObjectData(spawnId)); + + // Creatures on transport + for (ObjectGuid::LowType spawnId : guids.creatures) + CreateNPCPassenger(spawnId, sObjectMgr->GetCreatureData(spawnId)); } } diff --git a/src/server/game/Globals/ObjectMgr.cpp b/src/server/game/Globals/ObjectMgr.cpp index 301ff49ec8e..67bf9047c82 100644 --- a/src/server/game/Globals/ObjectMgr.cpp +++ b/src/server/game/Globals/ObjectMgr.cpp @@ -2338,6 +2338,19 @@ void ObjectMgr::LoadCreatures() TC_LOG_INFO("server.loading", ">> Loaded {} creatures in {} ms", _creatureDataStore.size(), GetMSTimeDiffToNow(oldMSTime)); } +CellObjectGuids const* ObjectMgr::GetCellObjectGuids(uint16 mapid, uint8 spawnMode, uint32 cell_id) +{ + if (CellObjectGuidsMap const* mapGuids = Trinity::Containers::MapGetValuePtr(_mapObjectGuidsStore, MAKE_PAIR32(mapid, spawnMode))) + return Trinity::Containers::MapGetValuePtr(*mapGuids, cell_id); + + return nullptr; +} + +CellObjectGuidsMap const* ObjectMgr::GetMapObjectGuids(uint16 mapid, uint8 spawnMode) +{ + return Trinity::Containers::MapGetValuePtr(_mapObjectGuidsStore, MAKE_PAIR32(mapid, spawnMode)); +} + void ObjectMgr::AddCreatureToGrid(ObjectGuid::LowType guid, CreatureData const* data) { uint8 mask = data->spawnMask; diff --git a/src/server/game/Globals/ObjectMgr.h b/src/server/game/Globals/ObjectMgr.h index aff5d05118d..6eb39767842 100644 --- a/src/server/game/Globals/ObjectMgr.h +++ b/src/server/game/Globals/ObjectMgr.h @@ -1281,15 +1281,9 @@ class TC_GAME_API ObjectMgr return nullptr; } - CellObjectGuids const& GetCellObjectGuids(uint16 mapid, uint8 spawnMode, uint32 cell_id) - { - return _mapObjectGuidsStore[MAKE_PAIR32(mapid, spawnMode)][cell_id]; - } + CellObjectGuids const* GetCellObjectGuids(uint16 mapid, uint8 spawnMode, uint32 cell_id); - CellObjectGuidsMap const& GetMapObjectGuids(uint16 mapid, uint8 spawnMode) - { - return _mapObjectGuidsStore[MAKE_PAIR32(mapid, spawnMode)]; - } + CellObjectGuidsMap const* GetMapObjectGuids(uint16 mapid, uint8 spawnMode); /** * Gets temp summon data for all creatures of specified group. diff --git a/src/server/game/Grids/ObjectGridLoader.cpp b/src/server/game/Grids/ObjectGridLoader.cpp index bcb6e6b41af..b5e5826f042 100644 --- a/src/server/game/Grids/ObjectGridLoader.cpp +++ b/src/server/game/Grids/ObjectGridLoader.cpp @@ -121,15 +121,15 @@ void LoadHelper(CellGuidSet const& guid_set, CellCoord &cell, GridRefManager<T> void ObjectGridLoader::Visit(GameObjectMapType &m) { CellCoord cellCoord = i_cell.GetCellCoord(); - CellObjectGuids const& cell_guids = sObjectMgr->GetCellObjectGuids(i_map->GetId(), i_map->GetSpawnMode(), cellCoord.GetId()); - LoadHelper(cell_guids.gameobjects, cellCoord, m, i_gameObjects, i_map); + if (CellObjectGuids const* cell_guids = sObjectMgr->GetCellObjectGuids(i_map->GetId(), i_map->GetSpawnMode(), cellCoord.GetId())) + LoadHelper(cell_guids->gameobjects, cellCoord, m, i_gameObjects, i_map); } void ObjectGridLoader::Visit(CreatureMapType &m) { CellCoord cellCoord = i_cell.GetCellCoord(); - CellObjectGuids const& cell_guids = sObjectMgr->GetCellObjectGuids(i_map->GetId(), i_map->GetSpawnMode(), cellCoord.GetId()); - LoadHelper(cell_guids.creatures, cellCoord, m, i_creatures, i_map); + if (CellObjectGuids const* cell_guids = sObjectMgr->GetCellObjectGuids(i_map->GetId(), i_map->GetSpawnMode(), cellCoord.GetId())) + LoadHelper(cell_guids->creatures, cellCoord, m, i_creatures, i_map); } void ObjectWorldLoader::Visit(CorpseMapType& /*m*/) |