diff --git a/src/DotRecast.Detour.TileCache/DtTileCacheBuilder.cs b/src/DotRecast.Detour.TileCache/DtTileCacheBuilder.cs index 0d5437ca..2247ef38 100644 --- a/src/DotRecast.Detour.TileCache/DtTileCacheBuilder.cs +++ b/src/DotRecast.Detour.TileCache/DtTileCacheBuilder.cs @@ -1408,8 +1408,13 @@ public static void RemoveVertex(DtTileCachePolyMesh mesh, int rem, int maxTris) int nv = CountPolyVerts(mesh.polys, p, maxVertsPerPoly); bool hasRem = false; for (int j = 0; j < nv; ++j) + { if (mesh.polys[p + j] == rem) + { hasRem = true; + } + } + if (hasRem) { // Collect edges which does not touch the removed vertex. @@ -1450,8 +1455,12 @@ public static void RemoveVertex(DtTileCachePolyMesh mesh, int rem, int maxTris) int p = i * maxVertsPerPoly * 2; int nv = CountPolyVerts(mesh.polys, p, maxVertsPerPoly); for (int j = 0; j < nv; ++j) + { if (mesh.polys[p + j] > rem) + { mesh.polys[p + j]--; + } + } } for (int i = 0; i < nedges; ++i) @@ -1606,10 +1615,13 @@ public static void RemoveVertex(DtTileCachePolyMesh mesh, int rem, int maxTris) { if (mesh.npolys >= maxTris) break; + int p = mesh.npolys * maxVertsPerPoly * 2; Array.Fill(mesh.polys, DT_TILECACHE_NULL_IDX, p, maxVertsPerPoly * 2); + for (int j = 0; j < maxVertsPerPoly; ++j) mesh.polys[p + j] = polys[i * maxVertsPerPoly + j]; + mesh.areas[mesh.npolys] = pareas[i]; mesh.npolys++; if (mesh.npolys > maxTris)