{"record":{"id":"c3e9a514df8614bd","repo":"egametang/ET","slug":"rcbuildpolymesh-too-many-vertices-maxvertices","errorCode":null,"errorMessage":"rcBuildPolyMesh: Too many vertices {maxVertices}","messagePattern":"rcBuildPolyMesh: Too many vertices (.+?)","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"critical","filePath":"Packages/cn.etetet.recast/Scripts/Core/Share/Recast/RecastMesh.cs","lineNumber":996,"sourceCode":"            mesh.borderSize = cset.borderSize;\n            mesh.maxEdgeError = cset.maxError;\n\n            int maxVertices = 0;\n            int maxTris = 0;\n            int maxVertsPerCont = 0;\n            for (int i = 0; i < cset.conts.Count; ++i)\n            {\n                // Skip null contours.\n                if (cset.conts[i].nverts < 3)\n                    continue;\n                maxVertices += cset.conts[i].nverts;\n                maxTris += cset.conts[i].nverts - 2;\n                maxVertsPerCont = Math.Max(maxVertsPerCont, cset.conts[i].nverts);\n            }\n\n            if (maxVertices >= 0xfffe)\n            {\n                throw new Exception(\"rcBuildPolyMesh: Too many vertices \" + maxVertices);\n            }\n\n            int[] vflags = new int[maxVertices];\n\n            mesh.verts = new int[maxVertices * 3];\n            mesh.polys = new int[maxTris * nvp * 2];\n            Array.Fill(mesh.polys, RC_MESH_NULL_IDX);\n            mesh.regs = new int[maxTris];\n            mesh.areas = new int[maxTris];\n\n            mesh.nverts = 0;\n            mesh.npolys = 0;\n            mesh.nvp = nvp;\n            mesh.maxpolys = maxTris;\n\n            int[] nextVert = new int[maxVertices];\n\n            int[] firstVert = new int[VERTEX_BUCKET_COUNT];","sourceCodeStart":978,"sourceCodeEnd":1014,"githubUrl":"https://github.com/egametang/ET/blob/5cab01f7a8bee5f49f4781eebe9e2b1c6d7ebe0f/Packages/cn.etetet.recast/Scripts/Core/Share/Recast/RecastMesh.cs#L978-L1014","documentation":"rcBuildPolyMesh sums the vertex count across every contour in the input contour set before allocating the polymesh. Because internal indices pack into 16 bits, a combined vertex total of 0xfffe (65534) or more is rejected up front. The throw is a hard capacity guard at allocation time, before any polygon work begins.","triggerScenarios":"Calling rcBuildPolyMesh(ctx, cset, nvp) where the sum of cset.conts[*].nverts over all non-null contours (nverts >= 3) reaches or exceeds 65534. This is driven purely by the input ContourSet density.","commonSituations":"Baking a single oversized navmesh tile from a very large or geometrically complex level; cellSize too small producing huge contour counts; merging many disjoint walkable regions into one tile; feeding un-partitioned geometry (no region/watershed partitioning) so contours stay enormous.","solutions":["Reduce tile size so each tile's contour set has far fewer than 65534 vertices.","Increase rcConfig.cellSize so each voxel covers more world area, shrinking contour vertex counts.","Verify you passed a properly partitioned CompactHeightfield (use RC_PARTITION_WATERSHED or RC_PARTITION_MONOTONE) so large regions are split.","If a deliberately large mesh is required, split the world into multiple Detour tiles and build a DtNavMesh from the tile set instead of one monolithic polymesh."],"exampleFix":"// before: one giant tile\nrcConfig cfg = new() { cellSize = 0.1f, tileSize = 0 };\n// after: tile the world and cap per-tile vertex counts\nrcConfig cfg = new() { cellSize = 0.2f, tileSize = 64 };\n// build each tile separately, then assemble into DtNavMesh","handlingStrategy":"validation","validationCode":"// Before calling rcBuildPolyMesh, sum contour vertices and reject early\nint totalVerts = 0;\nfor (int i = 0; i < cset.conts.Count; i++)\n    if (cset.conts[i].nverts >= 3)\n        totalVerts += cset.conts[i].nverts;\nif (totalVerts >= 0xfffe)\n    throw new InvalidOperationException($\"rcBuildPolyMesh input too large: {totalVerts} verts. Tile the world or raise cellSize.\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always set rcConfig.tileSize for large worlds so no single build approaches 65534 vertices.","Log total contour vertex counts during bake to catch runaway geometry early.","Profile cellSize against your largest level before shipping."],"tags":["recast","navmesh","capacity-limit","vertex-count"],"backgroundTag":null,"analyzedSha":"5cab01f7a8bee5f49f4781eebe9e2b1c6d7ebe0f","analyzedAt":"2026-08-13T21:10:40.377Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}