1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-01 03:21:41 +00:00

Update next tile_id when there is a duplicate in navmeshdb

Disable writes on failure to update next tile_id to avoid further errors.
This commit is contained in:
elsid 2024-02-07 11:14:31 +01:00
parent 557e83d502
commit a7da604332
No known key found for this signature in database
GPG Key ID: 4DE04C198CBA7625
2 changed files with 54 additions and 0 deletions

View File

@ -299,4 +299,41 @@ namespace
<< " present=" << (present.find(tilePosition) != present.end());
}
}
TEST_F(DetourNavigatorAsyncNavMeshUpdaterTest, next_tile_id_should_be_updated_on_duplicate)
{
mRecastMeshManager.setWorldspace(mWorldspace, nullptr);
addHeightFieldPlane(mRecastMeshManager);
addObject(mBox, mRecastMeshManager);
auto db = std::make_unique<NavMeshDb>(":memory:", std::numeric_limits<std::uint64_t>::max());
NavMeshDb* const dbPtr = db.get();
AsyncNavMeshUpdater updater(mSettings, mRecastMeshManager, mOffMeshConnectionsManager, std::move(db));
const TileId nextTileId(dbPtr->getMaxTileId() + 1);
ASSERT_EQ(dbPtr->insertTile(nextTileId, "worldspace", TilePosition{}, TileVersion{ 1 }, {}, {}), 1);
const auto navMeshCacheItem = std::make_shared<GuardedNavMeshCacheItem>(1, mSettings);
const TilePosition tilePosition{ 0, 0 };
const std::map<TilePosition, ChangeType> changedTiles{ { tilePosition, ChangeType::add } };
updater.post(mAgentBounds, navMeshCacheItem, mPlayerTile, mWorldspace, changedTiles);
updater.wait(WaitConditionType::allJobsDone, &mListener);
const AgentBounds agentBounds{ CollisionShapeType::Cylinder, { 29, 29, 66 } };
updater.post(agentBounds, navMeshCacheItem, mPlayerTile, mWorldspace, changedTiles);
updater.wait(WaitConditionType::allJobsDone, &mListener);
updater.stop();
const auto recastMesh = mRecastMeshManager.getMesh(mWorldspace, tilePosition);
ASSERT_NE(recastMesh, nullptr);
ShapeId nextShapeId{ 1 };
const std::vector<DbRefGeometryObject> objects = makeDbRefGeometryObjects(recastMesh->getMeshSources(),
[&](const MeshSource& v) { return resolveMeshSource(*dbPtr, v, nextShapeId); });
const auto tile = dbPtr->findTile(
mWorldspace, tilePosition, serialize(mSettings.mRecast, agentBounds, *recastMesh, objects));
ASSERT_TRUE(tile.has_value());
EXPECT_EQ(tile->mTileId, 2);
EXPECT_EQ(tile->mVersion, navMeshFormatVersion);
}
}

View File

@ -814,6 +814,23 @@ namespace DetourNavigator
Log(Debug::Warning)
<< "Writes to navmeshdb are disabled to avoid concurrent writes from multiple processes";
}
else if (message.find("UNIQUE constraint failed: tiles.tile_id") != std::string_view::npos)
{
Log(Debug::Warning) << "Found duplicate navmeshdb tile_id, please report the "
"issue to https://gitlab.com/OpenMW/openmw/-/issues, attach openmw.log: "
<< mNextTileId;
try
{
mNextTileId = TileId(mDb->getMaxTileId() + 1);
Log(Debug::Info) << "Updated navmeshdb tile_id to: " << mNextTileId;
}
catch (const std::exception& e)
{
mWriteToDb = false;
Log(Debug::Warning)
<< "Failed to update next tile_id, writes to navmeshdb are disabled: " << e.what();
}
}
}
}
};