BatchMesh's maxVertexCount and maxIndexCount, can't you customize the values yourself?

BatchMesh’s maxVertexCount and maxIndexCount, can’t you customize the values yourself? If 180000000 is set, an error Array buffer allocation failed will be reported. Is there an upper limit to this value?
Demo
This is the demo link. 180000000 has been set in it and an error has been reported.

Iirc 16384 or 65536 - can’t remember which one (or I may remember wrong entirely, but it’s some power of 2.)

For vertex array that limit will be 3x lower than for indices.

Keep in mind BatchMesh is going to allocate all of that memory up front. The memory allocation is not resizable, without creating a new BatchMesh and disposing the old one. It’s OK to allocate a bit more than you think you’ll need, but allocating space for 180 million vertices is far too much.

I’m not sure what the hard limit is, but if you have more vertices in a mesh than pixels on your screen, something is very wrong. :slight_smile:

1 Like

@donmccurdy

Should we first obtain the vertex numbers and indexes of all the geometries that need to be added this time to pre-allocate memory?

But when I use the following code to set the vertices and indexes, the error Array buffer allocate failed will also be reported.

const geometryCount = count;
const maxVertexCount = geometry.attributes.position.count * count;
const maxIndexCount = geometry.index.count * count;

I think it’s common to over-allocate somewhat (say, +25-50%) especially if you’re planning to add/remove things dynamically. If each geometry is identical, InstancedMesh would be more appropriate. If you’ve set the maximums at least as large as what you need, and it’s not a tab-crashing number like 50M+, and you’re still seeing errors, then we might need to look more closely at the demo.