{"record":{"id":"f9cbf48eb3667ec9","repo":"mrdoob/three.js","slug":"three-batchedmesh-geometry-vertex-values-are-bein","errorCode":null,"errorMessage":"THREE.BatchedMesh: Geometry vertex values are being used outside the range ${ maxIndexCount }. Cannot shrink further.","messagePattern":"THREE\\.BatchedMesh: Geometry vertex values are being used outside the range (.+?)\\. Cannot shrink further\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/objects/BatchedMesh.js","lineNumber":1334,"sourceCode":"\n\t}\n\n\t/**\n\t * Resizes the available space in the batch's vertex and index buffer attributes to the provided sizes.\n\t * If the provided arguments shrink the geometry buffers but there is not enough unused space at the\n\t * end of the geometry attributes then an error is thrown.\n\t *\n\t * @param {number} maxVertexCount - The maximum number of vertices to be used by all unique geometries to resize to.\n\t * @param {number} maxIndexCount - The maximum number of indices to be used by all unique geometries to resize to.\n\t*/\n\tsetGeometrySize( maxVertexCount, maxIndexCount ) {\n\n\t\t// Check if we can shrink to the requested vertex attribute size\n\t\tconst validRanges = [ ...this._geometryInfo ].filter( info => info.active );\n\t\tconst requiredVertexLength = Math.max( ...validRanges.map( range => range.vertexStart + range.reservedVertexCount ) );\n\t\tif ( requiredVertexLength > maxVertexCount ) {\n\n\t\t\tthrow new Error( `THREE.BatchedMesh: Geometry vertex values are being used outside the range ${ maxIndexCount }. Cannot shrink further.` );\n\n\t\t}\n\n\t\t// Check if we can shrink to the requested index attribute size\n\t\tif ( this.geometry.index ) {\n\n\t\t\tconst requiredIndexLength = Math.max( ...validRanges.map( range => range.indexStart + range.reservedIndexCount ) );\n\t\t\tif ( requiredIndexLength > maxIndexCount ) {\n\n\t\t\t\tthrow new Error( `THREE.BatchedMesh: Geometry index values are being used outside the range ${ maxIndexCount }. Cannot shrink further.` );\n\n\t\t\t}\n\n\t\t}\n\n\t\t//\n\n\t\t// dispose of the previous geometry","sourceCodeStart":1316,"sourceCodeEnd":1352,"githubUrl":"https://github.com/mrdoob/three.js/blob/da05705fa31f02710c19772a2aa70c7454807f0c/src/objects/BatchedMesh.js#L1316-L1352","documentation":"Thrown by BatchedMesh.setGeometrySize() when shrinking the VERTEX buffer would cut into a reserved range still in use. WARNING: the message text is misleading — it reports the maxIndexCount value even though this check is the vertex check; the real offending parameter is maxVertexCount. The condition is requiredVertexLength > maxVertexCount where requiredVertexLength is the max over all active ranges of (vertexStart + reservedVertexCount).","triggerScenarios":"Calling batchedMesh.setGeometrySize(maxVertexCount, maxIndexCount) with a maxVertexCount smaller than the highest vertexStart + reservedVertexCount among active geometry slots. Attempting to compact the vertex buffer while geometries still occupy the tail.","commonSituations":"Memory-reduction pass that lowers capacity after content was added; misreading the error message and lowering the wrong parameter (index instead of vertex) due to the message bug.","solutions":["Read the message carefully: despite saying maxIndexCount, the fix is to raise maxVertexCount (or delete/compact geometries that occupy the high vertex range).","Before calling setGeometrySize, compute Math.max(...activeRanges.map(r => r.vertexStart + r.reservedVertexCount)) and pass a maxVertexCount at least that large.","deleteGeometry on slots whose reservations extend into the tail, then shrink.","Report/file the message-text bug upstream if it confuses operators."],"exampleFix":"// before\nbatch.setGeometrySize( 500, 1000 ); // throws; message quotes 1000 but vertex floor was exceeded\n\n// after\nconst requiredVerts = Math.max( ...batch.geometryInfo.filter(i=>i.active).map(i => i.vertexStart + i.reservedVertexCount) );\nbatch.setGeometrySize( requiredVerts, 1000 );","handlingStrategy":"validation","validationCode":"const requiredVerts = Math.max(\n  ...batchedMesh.geometryInfo.filter( i => i.active ).map( i => i.vertexStart + i.reservedVertexCount )\n);\nif ( maxVertexCount >= requiredVerts ) batchedMesh.setGeometrySize( maxVertexCount, maxIndexCount );","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Remember the message reports maxIndexCount but the fix is the VERTEX parameter — don't be misled.","Compute the required vertex floor before shrinking.","Delete geometry slots occupying the high vertex range before shrinking.","Re-allocate and migrate geometries if aggressive shrinking is needed."],"tags":["batchedmesh","resize","vertex-buffer","misleading-message"],"backgroundTag":null,"analyzedSha":"da05705fa31f02710c19772a2aa70c7454807f0c","analyzedAt":"2026-08-12T22:51:37.160Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}