{"record":{"id":"9adc6a444335f7ef","repo":"mrdoob/three.js","slug":"three-batchedmesh-geometry-index-values-are-being","errorCode":null,"errorMessage":"THREE.BatchedMesh: Geometry index values are being used outside the range ${ maxIndexCount }. Cannot shrink further.","messagePattern":"THREE\\.BatchedMesh: Geometry index values are being used outside the range (.+?)\\. Cannot shrink further\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/objects/BatchedMesh.js","lineNumber":1344,"sourceCode":"\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\n\t\tconst oldGeometry = this.geometry;\n\t\toldGeometry.dispose();\n\n\t\t// recreate the geometry needed based on the previous variant\n\t\tthis._maxVertexCount = maxVertexCount;\n\t\tthis._maxIndexCount = maxIndexCount;\n\n\t\tif ( this._geometryInitialized ) {\n\n\t\t\tthis._geometryInitialized = false;","sourceCodeStart":1326,"sourceCodeEnd":1362,"githubUrl":"https://github.com/mrdoob/three.js/blob/da05705fa31f02710c19772a2aa70c7454807f0c/src/objects/BatchedMesh.js#L1326-L1362","documentation":"Thrown by BatchedMesh.setGeometrySize() when shrinking the INDEX buffer would cut into a reserved index range still in use. The condition is requiredIndexLength > maxIndexCount where requiredIndexLength is the max over active ranges of (indexStart + reservedIndexCount). Only checked when the batch geometry has an index attribute.","triggerScenarios":"Calling batchedMesh.setGeometrySize(maxVertexCount, maxIndexCount) with maxIndexCount smaller than the highest indexStart + reservedIndexCount among active geometry slots, on an indexed batch.","commonSituations":"Compacting index memory after removing geometries but before their index reservations are released; lowering index capacity while indexed meshes still occupy the tail.","solutions":["Compute Math.max(...activeRanges.map(r => r.indexStart + r.reservedIndexCount)) and pass a maxIndexCount at least that large.","deleteGeometry on slots whose index reservations extend into the tail before shrinking.","If the batch is non-indexed, this check is skipped — consider whether indexing is required.","Re-allocate the BatchedMesh at the desired index capacity and migrate geometries if aggressive shrinking is needed."],"exampleFix":"// before\nbatch.setGeometrySize( 10000, 500 ); // throws: indexed geometry needs more\n\n// after\nconst requiredIndices = Math.max( ...batch.geometryInfo.filter(i=>i.active).map(i => i.indexStart + i.reservedIndexCount) );\nbatch.setGeometrySize( 10000, requiredIndices );","handlingStrategy":"validation","validationCode":"const requiredIndices = Math.max(\n  ...batchedMesh.geometryInfo.filter( i => i.active ).map( i => i.indexStart + i.reservedIndexCount )\n);\nif ( maxIndexCount >= requiredIndices ) batchedMesh.setGeometrySize( maxVertexCount, maxIndexCount );","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Compute the required index floor before shrinking.","Delete geometry slots occupying the high index range before shrinking.","Remember this check only runs when the batch geometry is indexed.","Re-allocate and migrate if aggressive shrinking is needed."],"tags":["batchedmesh","resize","index-buffer","capacity"],"backgroundTag":null,"analyzedSha":"da05705fa31f02710c19772a2aa70c7454807f0c","analyzedAt":"2026-08-12T22:51:37.160Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}