diff --git a/components/detournavigator/tilecachedrecastmeshmanager.cpp b/components/detournavigator/tilecachedrecastmeshmanager.cpp index d1f586f85c..314e7641e3 100644 --- a/components/detournavigator/tilecachedrecastmeshmanager.cpp +++ b/components/detournavigator/tilecachedrecastmeshmanager.cpp @@ -38,8 +38,9 @@ namespace DetourNavigator return false; std::vector tilesPositions; { + const TilesPositionsRange range = makeTilesPositionsRange(shape.getShape(), transform, mSettings); const std::lock_guard lock(mMutex); - getTilesPositions(makeTilesPositionsRange(shape.getShape(), transform, mSettings), + getTilesPositions(range, [&] (const TilePosition& tilePosition) { if (addTile(id, shape, transform, areaType, tilePosition, mTiles)) diff --git a/components/detournavigator/tilecachedrecastmeshmanager.hpp b/components/detournavigator/tilecachedrecastmeshmanager.hpp index 88face24ce..efd70477d3 100644 --- a/components/detournavigator/tilecachedrecastmeshmanager.hpp +++ b/components/detournavigator/tilecachedrecastmeshmanager.hpp @@ -38,7 +38,6 @@ namespace DetourNavigator bool changed = false; std::vector newTiles; { - const std::lock_guard lock(mMutex); const auto onTilePosition = [&] (const TilePosition& tilePosition) { if (std::binary_search(currentTiles.begin(), currentTiles.end(), tilePosition)) @@ -57,7 +56,9 @@ namespace DetourNavigator changed = true; } }; - getTilesPositions(makeTilesPositionsRange(shape.getShape(), transform, mSettings), onTilePosition); + const TilesPositionsRange range = makeTilesPositionsRange(shape.getShape(), transform, mSettings); + const std::lock_guard lock(mMutex); + getTilesPositions(range, onTilePosition); std::sort(newTiles.begin(), newTiles.end()); for (const auto& tile : currentTiles) {