Babylon 5.5.5, Freeze on collision?

Hey team,
We noted a new issue with Babylon 5 that we never had previously.

When colliding with objects we sometimes hit a .copyFromPoints error that freezes the engine.

Uncaught TypeError: Cannot read properties of undefined (reading 'x')
    at Plane.copyFromPoints (math.plane.ts:114:27)
    at Collider._testTriangle (collider.ts:244:43)
    at Collider._collide (collider.ts:523:26)
    at Mesh.AbstractMesh._collideForSubMesh (abstractMesh.ts:1761:18)
    at Mesh.AbstractMesh._processCollisionsForSubMeshes (abstractMesh.ts:1793:18)
    at Mesh.AbstractMesh._checkCollision (abstractMesh.ts:1818:14)
    at DefaultCollisionCoordinator._collideWithWorld (collisionCoordinator.ts:89:22)
    at DefaultCollisionCoordinator.getNewPosition (collisionCoordinator.ts:47:14)

According to this post below, the solution suggests the issue to come from a bad mesh.

The error is the same as in the post above and the console guides us to this:

However our meshes have been fine with collision since 4.2.0 and doing a quick console.log doesn’t seem to reveal any faulty mesh.
console.log(!(indices.length % 3))

I’ve also been trying to reproduce the bug in

but I can’t do it.
The playground contains Polytext meshes (3D text as mesh).

How we reproduce it in our game is we keep bumping into things and it eventually causes the error, I noted that spawning directly inside the object can also cause issues

Therefore all I can do is ask what could be leading to such error? What could lead to Babylon failing with collision?

I reproduced it in the follow playground:
In that playground you spawn somewhat within a polytext and therefore get bumped to the side. However in this case, the engine crashes.
All I did was change generateText('Poly',scene) (line 251)
to generateText('Polyyyygggggggggggggggg',scene)

Hello! Taking a look at this.

Indeed, this seems to be coming from a bad mesh. Following the exception’s trace leads us to this part of the collision:

where we’re getting p1, p2 and p3 as undefined. By checking the values used to find them, we see that, for i = 2976, indices[i] = 1538, which is greater than the length of the pts array:

So, one of the meshes has an invalid index somewhere.

1 Like

Hey @carolhmj !
You’re right, there is something fishy going on here.
If the first letter between the two polytexts doesnt match, there is no crash
If the order of loading is changed, i.e. polyVeryLong has a timeout for 3000 ms it wont crash.
The numbers of normals generated for each polytext is exactly 9504 which is highly suspicious.

Here is another trimmed down version of the playground

Could this be something wrong with BABYLON.Mesh.MergeMeshes in BB 5 ?

Actually merge meshes has been optimized to prevent memory dupplication :slight_smile:

So in your case as you pass down the same indices array to both mesh and knowing than everything is merged in the first mesh so here the letter P you end up after the first merge with a huge array of indices not matching the rest of your data.

I would recommend to clone the array: by adding slice on the indices array,


Oh wow, that’s pretty humbling.

Thanks for this!

1 Like