BufferGeometry.calculateBoundingSphere fails due to NaN values

Hi, I posted an issue some time ago BufferGeometry.calculateBoundingSphere fails due to NaN values · Issue #25069 · mrdoob/three.js · GitHub
but it was closed, perhaps I wasn’t too clear.

I had an example there:

 // vertices - is the plain float32 array of 321544 values in total
 const vbVertices = new Float32BufferAttribute(vertices, 3)
 geometry.setAttribute('position', vbVertices)

Inside BufferAttribute there is code:

this.count = array !== undefined ? array.length / itemSize : 0;

In my case, due to floating point errors, this.count is set to 107181.333. This will affect all for loops that iterate over elements in the attribute, e.g.

for (i = 0; i< this.count; ++i) {… }

If this.count is not integer as in my case, it will give unwanted extra iteration. BufferGeometry.computeBoundingSphere is an example, it will think there’s NaN values, but I don’t have NaN values in my buffer.

Your buffer attribute is not setup correctly. The length of the array must be a multiple of your item size (in this instance 3).

You are right… sorry for your time. My buffer had one extra value that shouldn’t be there.

I checked it blindly using a calculator in programmer’s mode, it just throws fractional part, 321544 / 3 = 107181. My fault.