Increase mutex scope in TileCachedRecastMeshManager functions

Which are called from the main thread.
crashfix_debugdraw
elsid 2 years ago
parent e1bed86d7e
commit 2885885331
No known key found for this signature in database
GPG Key ID: 4DE04C198CBA7625

@ -149,15 +149,15 @@ namespace DetourNavigator
else
{
const btVector3 shift = Misc::Convert::toBullet(getWaterShift3d(cellPosition, cellSize, level));
const auto worldspaceTiles = mWorldspaceTiles.lock();
getTilesPositions(makeTilesPositionsRange(cellSize, shift, mSettings),
[&] (const TilePosition& tilePosition)
{
const auto locked = mWorldspaceTiles.lock();
auto tile = locked->mTiles.find(tilePosition);
if (tile == locked->mTiles.end())
auto tile = worldspaceTiles->mTiles.find(tilePosition);
if (tile == worldspaceTiles->mTiles.end())
{
const TileBounds tileBounds = makeRealTileBoundsWithBorder(mSettings, tilePosition);
tile = locked->mTiles.emplace_hint(tile, tilePosition,
tile = worldspaceTiles->mTiles.emplace_hint(tile, tilePosition,
std::make_shared<CachedRecastMeshManager>(tileBounds, mTilesGeneration));
}
if (tile->second->addWater(cellPosition, cellSize, level))
@ -180,20 +180,22 @@ namespace DetourNavigator
if (object == mWaterTilesPositions.end())
return std::nullopt;
std::optional<Water> result;
for (const auto& tilePosition : object->second)
{
const auto locked = mWorldspaceTiles.lock();
const auto tile = locked->mTiles.find(tilePosition);
if (tile == locked->mTiles.end())
continue;
const auto tileResult = tile->second->removeWater(cellPosition);
if (tile->second->isEmpty())
const auto worldspaceTiles = mWorldspaceTiles.lock();
for (const auto& tilePosition : object->second)
{
locked->mTiles.erase(tile);
++mTilesGeneration;
const auto tile = worldspaceTiles->mTiles.find(tilePosition);
if (tile == worldspaceTiles->mTiles.end())
continue;
const auto tileResult = tile->second->removeWater(cellPosition);
if (tile->second->isEmpty())
{
worldspaceTiles->mTiles.erase(tile);
++mTilesGeneration;
}
if (tileResult && !result)
result = tileResult;
}
if (tileResult && !result)
result = tileResult;
}
mWaterTilesPositions.erase(object);
if (result)
@ -214,23 +216,25 @@ namespace DetourNavigator
bool result = false;
getTilesPositions(makeTilesPositionsRange(cellSize, shift, mSettings),
[&] (const TilePosition& tilePosition)
{
const auto locked = mWorldspaceTiles.lock();
auto tile = locked->mTiles.find(tilePosition);
if (tile == locked->mTiles.end())
{
const TileBounds tileBounds = makeRealTileBoundsWithBorder(mSettings, tilePosition);
tile = locked->mTiles.emplace_hint(tile, tilePosition,
std::make_shared<CachedRecastMeshManager>(tileBounds, mTilesGeneration));
}
if (tile->second->addHeightfield(cellPosition, cellSize, shape))
{
const auto worldspaceTiles = mWorldspaceTiles.lock();
getTilesPositions(makeTilesPositionsRange(cellSize, shift, mSettings),
[&] (const TilePosition& tilePosition)
{
tilesPositions.push_back(tilePosition);
result = true;
}
});
auto tile = worldspaceTiles->mTiles.find(tilePosition);
if (tile == worldspaceTiles->mTiles.end())
{
const TileBounds tileBounds = makeRealTileBoundsWithBorder(mSettings, tilePosition);
tile = worldspaceTiles->mTiles.emplace_hint(tile, tilePosition,
std::make_shared<CachedRecastMeshManager>(tileBounds, mTilesGeneration));
}
if (tile->second->addHeightfield(cellPosition, cellSize, shape))
{
tilesPositions.push_back(tilePosition);
result = true;
}
});
}
if (result)
++mRevision;
@ -244,20 +248,22 @@ namespace DetourNavigator
if (object == mHeightfieldTilesPositions.end())
return std::nullopt;
std::optional<SizedHeightfieldShape> result;
for (const auto& tilePosition : object->second)
{
const auto locked = mWorldspaceTiles.lock();
const auto tile = locked->mTiles.find(tilePosition);
if (tile == locked->mTiles.end())
continue;
const auto tileResult = tile->second->removeHeightfield(cellPosition);
if (tile->second->isEmpty())
const auto worldspaceTiles = mWorldspaceTiles.lock();
for (const auto& tilePosition : object->second)
{
locked->mTiles.erase(tile);
++mTilesGeneration;
const auto tile = worldspaceTiles->mTiles.find(tilePosition);
if (tile == worldspaceTiles->mTiles.end())
continue;
const auto tileResult = tile->second->removeHeightfield(cellPosition);
if (tile->second->isEmpty())
{
worldspaceTiles->mTiles.erase(tile);
++mTilesGeneration;
}
if (tileResult && !result)
result = tileResult;
}
if (tileResult && !result)
result = tileResult;
}
mHeightfieldTilesPositions.erase(object);
if (result)

@ -165,7 +165,7 @@ namespace DetourNavigator
bool addTile(const ObjectId id, const CollisionShape& shape, const btTransform& transform,
const AreaType areaType, const TilePosition& tilePosition, TilesMap& tiles);
bool updateTile(const ObjectId id, const btTransform& transform, const AreaType areaType,
static bool updateTile(const ObjectId id, const btTransform& transform, const AreaType areaType,
const TilePosition& tilePosition, TilesMap& tiles);
std::optional<RemovedRecastMeshObject> removeTile(const ObjectId id, const TilePosition& tilePosition,

Loading…
Cancel
Save