{"record":{"id":"b6f0a7bd26d9ded9","repo":"egametang/ET","slug":"rcbuildpolymesh-too-many-polygons-mesh-npolys","errorCode":null,"errorMessage":"rcBuildPolyMesh: Too many polygons {mesh.npolys} (max:{maxTris}).","messagePattern":"rcBuildPolyMesh: Too many polygons (.+?) \\(max:(.+?)\\)\\.","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"critical","filePath":"Packages/cn.etetet.recast/Scripts/Core/Share/Recast/RecastMesh.cs","lineNumber":1136,"sourceCode":"                            // Could not merge any polygons, stop.\n                            break;\n                        }\n                    }\n                }\n\n                // Store polygons.\n                for (int j = 0; j < npolys; ++j)\n                {\n                    int p = mesh.npolys * nvp * 2;\n                    int q = j * nvp;\n                    for (int k = 0; k < nvp; ++k)\n                        mesh.polys[p + k] = polys[q + k];\n                    mesh.regs[mesh.npolys] = cont.reg;\n                    mesh.areas[mesh.npolys] = cont.area;\n                    mesh.npolys++;\n                    if (mesh.npolys > maxTris)\n                    {\n                        throw new Exception(\n                            \"rcBuildPolyMesh: Too many polygons \" + mesh.npolys + \" (max:\" + maxTris + \").\");\n                    }\n                }\n            }\n\n            // Remove edge vertices.\n            for (int i = 0; i < mesh.nverts; ++i)\n            {\n                if (vflags[i] != 0)\n                {\n                    if (!CanRemoveVertex(ctx, mesh, i))\n                        continue;\n                    RemoveVertex(ctx, mesh, i, maxTris);\n                    // Remove vertex\n                    // Note: mesh.nverts is already decremented inside RemoveVertex()!\n                    // Fixup vertex flags\n                    for (int j = i; j < mesh.nverts; ++j)\n                        vflags[j] = vflags[j + 1];","sourceCodeStart":1118,"sourceCodeEnd":1154,"githubUrl":"https://github.com/egametang/ET/blob/5cab01f7a8bee5f49f4781eebe9e2b1c6d7ebe0f/Packages/cn.etetet.recast/Scripts/Core/Share/Recast/RecastMesh.cs#L1118-L1154","documentation":"While storing polygons into the polymesh, rcBuildPolyMesh checks npolys against maxTris on every insert and throws once the pre-allocated polygon array is exceeded. maxTris is the sum of (contour.nverts - 2) over contours, so this trips when triangulation of the contours produces more polygons than the conservative estimate allowed for.","triggerScenarios":"The loop that converts simplified contour polygons into nvp-gons pushes mesh.npolys past maxTris. Happens when contours have many vertices and the per-contour (nverts-2) underestimate is collectively overrun, or when nvp (max verts per polygon) is small forcing many polygons.","commonSituations":"Setting rcConfig.maxVertsPerPoly low (e.g. 3 = pure triangles) on geometry with large contours; degenerate or very noisy contour sets from aggressive simplification settings; mismatched nvp between contour generation and polygon storage.","solutions":["Increase rcConfig.maxVertsPerPoly (e.g. to 6, the Detour default) so large contours become fewer polygons.","Lower the input contour density (raise cellSize, raise contour simplification tolerance via contourSimplificationError).","Tile the world (set rcConfig.tileSize) so no single build exceeds the polygon budget.","Audit that the contour set wasn't accidentally built with nvp lower than intended."],"exampleFix":"// before: triangles only, explodes polygon count\ncfg.maxVertsPerPoly = 3;\n// after: allow convex polys up to 6 verts (Detour default)\ncfg.maxVertsPerPoly = 6;","handlingStrategy":"validation","validationCode":"// Pre-check polygon budget using the same formula as the allocator\nint maxTris = 0;\nfor (int i = 0; i < cset.conts.Count; i++)\n    if (cset.conts[i].nverts >= 3)\n        maxTris += cset.conts[i].nverts - 2;\nif (maxTris > 0xfffe)\n    throw new InvalidOperationException($\"rcBuildPolyMesh would exceed polygon budget: {maxTris}\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use maxVertsPerPoly >= 6 (Detour default) to keep polygon counts down.","Tile the world to bound per-tile polygon counts.","Watch contourSimplificationError: too-low values inflate contour vertex counts."],"tags":["recast","navmesh","capacity-limit","polygon-count"],"backgroundTag":null,"analyzedSha":"5cab01f7a8bee5f49f4781eebe9e2b1c6d7ebe0f","analyzedAt":"2026-08-13T21:10:40.377Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}