{"record":{"id":"17c900a201ac8156","repo":"egametang/ET","slug":"removevertex-too-many-polygons-mesh-npolys-max","errorCode":null,"errorMessage":"removeVertex: Too many polygons {mesh.npolys} (max:{maxTris}.","messagePattern":"removeVertex: Too many polygons (.+?) \\(max:(.+?)\\.","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"warning","filePath":"Packages/cn.etetet.recast/Scripts/Core/Share/Recast/RecastMesh.cs","lineNumber":958,"sourceCode":"                    }\n                }\n            }\n\n            // Store polygons.\n            for (int i = 0; i < npolys; ++i)\n            {\n                if (mesh.npolys >= maxTris)\n                    break;\n                int p = mesh.npolys * nvp * 2;\n                Array.Fill(mesh.polys, RC_MESH_NULL_IDX, p, (p + nvp * 2) - (p));\n                for (int j = 0; j < nvp; ++j)\n                    mesh.polys[p + j] = polys[i * nvp + j];\n                mesh.regs[mesh.npolys] = pregs[i];\n                mesh.areas[mesh.npolys] = pareas[i];\n                mesh.npolys++;\n                if (mesh.npolys > maxTris)\n                {\n                    throw new Exception(\"removeVertex: Too many polygons \" + mesh.npolys + \" (max:\" + maxTris + \".\");\n                }\n            }\n        }\n\n        /// @par\n        ///\n        /// @note If the mesh data is to be used to construct a Detour navigation mesh, then the upper\n        /// limit must be restricted to <= #DT_VERTS_PER_POLYGON.\n        ///\n        /// @see rcAllocPolyMesh, rcContourSet, rcPolyMesh, rcConfig\n        public static RcPolyMesh BuildPolyMesh(RcTelemetry ctx, RcContourSet cset, int nvp)\n        {\n            using var timer = ctx.ScopedTimer(RcTimerLabel.RC_TIMER_BUILD_POLYMESH);\n\n            RcPolyMesh mesh = new RcPolyMesh();\n            mesh.bmin = cset.bmin;\n            mesh.bmax = cset.bmax;\n            mesh.cs = cset.cs;","sourceCodeStart":940,"sourceCodeEnd":976,"githubUrl":"https://github.com/egametang/ET/blob/5cab01f7a8bee5f49f4781eebe9e2b1c6d7ebe0f/Packages/cn.etetet.recast/Scripts/Core/Share/Recast/RecastMesh.cs#L940-L976","documentation":"Thrown inside removeVertex (RecastMesh) when the number of generated polygons (mesh.npolys) exceeds maxTris during vertex removal and re-triangulation. Removing a shared vertex can fan out into many triangles; if the surrounding geometry is dense, the re-triangulation overflows the allocated polygon buffer.","triggerScenarios":"Removing a vertex shared by many polygons in dense mesh detail; maxTris (derived from the detail/triangle budget) too small for the fan-out; large complex contours feeding BuildPolyMesh.","commonSituations":"High-detail input meshes producing dense polymes; tile size too large concentrating polygons; nvp config causing many-triangle fans.","solutions":["Increase the maxTris / detail polygon budget passed to the mesh builder.","Reduce tile size so each tile's polygon count stays under the limit.","Simplify source geometry or increase contour simplification to lower polygon density.","Avoid manually removing highly-shared vertices; let the builder choose removables."],"exampleFix":"// before\nint maxTris = nvp * 4; // too small for dense tile\n\n// after\nint maxTris = Math.Max(nvp * 4, expectedPolyCount * 2);\n// and/or reduce cfg.tileSize","handlingStrategy":"validation","validationCode":"int maxTris = Math.Max(nvp * 4, expectedPolyCount * 2);\nif (maxTris < mesh.npolys + safetyMargin) throw new InvalidOperationException(\"maxTris too small for vertex removal\");","typeGuard":null,"tryCatchPattern":"try { RecastMesh.RemoveVertex(...); }\ncatch (Exception e) when (e.Message.Contains(\"Too many polygons\"))\n{ /* increase maxTris budget or reduce tile size, retry */ }","preventionTips":["Allocate a generous maxTris/detail polygon budget relative to expected density.","Reduce tile size to cap per-tile polygon count.","Increase contour simplification to lower polygon density.","Avoid removing highly-shared vertices; let the builder choose."],"tags":["recast","polymesh","capacity","config","triangulation"],"backgroundTag":null,"analyzedSha":"5cab01f7a8bee5f49f4781eebe9e2b1c6d7ebe0f","analyzedAt":"2026-08-13T21:10:40.377Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}