mrdoob/three.js · error · Error

THREE.BatchedMesh: Geometry vertex values are being used out

Error message

THREE.BatchedMesh: Geometry vertex values are being used outside the range ${ maxIndexCount }. Cannot shrink further.

What it means

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).

Source

Thrown at src/objects/BatchedMesh.js:1334

	}

	/**
	 * Resizes the available space in the batch's vertex and index buffer attributes to the provided sizes.
	 * If the provided arguments shrink the geometry buffers but there is not enough unused space at the
	 * end of the geometry attributes then an error is thrown.
	 *
	 * @param {number} maxVertexCount - The maximum number of vertices to be used by all unique geometries to resize to.
	 * @param {number} maxIndexCount - The maximum number of indices to be used by all unique geometries to resize to.
	*/
	setGeometrySize( maxVertexCount, maxIndexCount ) {

		// Check if we can shrink to the requested vertex attribute size
		const validRanges = [ ...this._geometryInfo ].filter( info => info.active );
		const requiredVertexLength = Math.max( ...validRanges.map( range => range.vertexStart + range.reservedVertexCount ) );
		if ( requiredVertexLength > maxVertexCount ) {

			throw new Error( `THREE.BatchedMesh: Geometry vertex values are being used outside the range ${ maxIndexCount }. Cannot shrink further.` );

		}

		// Check if we can shrink to the requested index attribute size
		if ( this.geometry.index ) {

			const requiredIndexLength = Math.max( ...validRanges.map( range => range.indexStart + range.reservedIndexCount ) );
			if ( requiredIndexLength > maxIndexCount ) {

				throw new Error( `THREE.BatchedMesh: Geometry index values are being used outside the range ${ maxIndexCount }. Cannot shrink further.` );

			}

		}

		//

		// dispose of the previous geometry

View on GitHub (pinned to da05705fa3)

Solutions

  1. Read the message carefully: despite saying maxIndexCount, the fix is to raise maxVertexCount (or delete/compact geometries that occupy the high vertex range).
  2. Before calling setGeometrySize, compute Math.max(...activeRanges.map(r => r.vertexStart + r.reservedVertexCount)) and pass a maxVertexCount at least that large.
  3. deleteGeometry on slots whose reservations extend into the tail, then shrink.
  4. Report/file the message-text bug upstream if it confuses operators.

Example fix

// before
batch.setGeometrySize( 500, 1000 ); // throws; message quotes 1000 but vertex floor was exceeded

// after
const requiredVerts = Math.max( ...batch.geometryInfo.filter(i=>i.active).map(i => i.vertexStart + i.reservedVertexCount) );
batch.setGeometrySize( requiredVerts, 1000 );
Defensive patterns

Strategy: validation

Validate before calling

const requiredVerts = Math.max(
  ...batchedMesh.geometryInfo.filter( i => i.active ).map( i => i.vertexStart + i.reservedVertexCount )
);
if ( maxVertexCount >= requiredVerts ) batchedMesh.setGeometrySize( maxVertexCount, maxIndexCount );

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of mrdoob/three.js@da05705fa3 (2026-08-12). Data as JSON: /api/errors/f9cbf48eb3667ec9. Report an issue: GitHub.