# Incorrect number of triangle points on collision \_testTriangle

**URL:** <https://forum.babylonjs.com/t/incorrect-number-of-triangle-points-on-collision-testtriangle/51108>\
**Category:** Bugs\
**Tags:** movewithcollisions\
**Created:** [June 6, 2024, 3:24pm UTC](https://forum.babylonjs.com/t/incorrect-number-of-triangle-points-on-collision-testtriangle/51108 "2024-06-06T15:24:41Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Caner](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/caner/32/15711_2.png) [@Caner](https://forum.babylonjs.com/u/Caner)\
**Post date:** [June 6, 2024, 3:24pm UTC](https://forum.babylonjs.com/t/incorrect-number-of-triangle-points-on-collision-testtriangle/51108/1 "2024-06-06T15:24:41Z")

</div>

Hello everyone!

I have a 3D model that gives an error on collision. Here is the PG Link: [https://playground.babylonjs.com/#KQT1V0#2](https://playground.babylonjs.com/#KQT1V0#2)

I could debug that in `AbstractMesh._collideForSubMesh`, one submesh had 5 vertices. Therefore eventually in `Collider._testTriangle`, one point is missing for a triangle. It is no direct relation but I checked the file in Babylon Sandbox and it’s a valid glTF.

How can I make it work? I appreciate any help.

Thank you!!!

---

<div class="post-metadata">

**Author:** ![Tricotou](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/tricotou/32/5844_2.png) [@Tricotou](https://forum.babylonjs.com/u/Tricotou)\
**Post date:** [June 6, 2024, 3:43pm UTC](https://forum.babylonjs.com/t/incorrect-number-of-triangle-points-on-collision-testtriangle/51108/2 "2024-06-06T15:43:38Z")

</div>

Hello 🙂

> [@Caner](#):
>
> one submesh had 5 vertices. Therefore eventually in `Collider._testTriangle`, one point is missing for a triangle

5 vertices is fine as long as triangles are defined on them. Doesn’t mean that necessary a triangle is missing… For example :

 ![Screenshot from 2024-06-06 17-41-46](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/4/0/40e1e0ef2cecbeb69c00bb6f7b04a8f93169e060.png)

* * *

That said, indeed the issue comes from topology. Your mesh `node0` is only edges, no surface :

 ![Screenshot from 2024-06-06 17-39-48](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/4/8/488a3498c4553be3e53bf2ecb4ef2a8a3495f04d.png)

Avoiding it solves the issue : [Playground](https://playground.babylonjs.com/#KQT1V0#3)

* * *

But still, I kinda agree it’s a bug. Best would be that it doesn’t trigger an error, but simply go through.

++  
Tricotou

---

<div class="post-metadata">

**Author:** ![Deltakosh](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/deltakosh/32/26635_2.png) [@Deltakosh](https://forum.babylonjs.com/u/Deltakosh)\
**Post date:** [June 6, 2024, 3:46pm UTC](https://forum.babylonjs.com/t/incorrect-number-of-triangle-points-on-collision-testtriangle/51108/3 "2024-06-06T15:46:44Z")

</div>

I academically agree but practically disagree 🙂  
The code for collisions is quite complex and I try to keep it as simple as possible. If we need to test for mesh validity per frame per triangle, the cost will be prohibitive

---

<div class="post-metadata">

**Author:** ![Tricotou](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/tricotou/32/5844_2.png) [@Tricotou](https://forum.babylonjs.com/u/Tricotou)\
**Post date:** [June 6, 2024, 3:52pm UTC](https://forum.babylonjs.com/t/incorrect-number-of-triangle-points-on-collision-testtriangle/51108/4 "2024-06-06T15:52:42Z")

</div>

> [@Deltakosh](#):
>
> If we need to test for mesh validity per frame per triangle, the cost will be prohibitive

Agreed. I was thinking about a topology check at first enabling of `mesh.checkCollisions = true;` in order not to trigger an error at collision check 🙂

---

<div class="post-metadata">

**Author:** ![Deltakosh](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/deltakosh/32/26635_2.png) [@Deltakosh](https://forum.babylonjs.com/u/Deltakosh)\
**Post date:** [June 6, 2024, 3:58pm UTC](https://forum.babylonjs.com/t/incorrect-number-of-triangle-points-on-collision-testtriangle/51108/5 "2024-06-06T15:58:31Z")

</div>

yes but even that could happen on a complex object in the middle of a frame. If i was able to run that off thread, I would sign right now but JS is still living like a caveman with no real thread support 😉

---

<div class="post-metadata">

**Author:** ![Caner](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/caner/32/15711_2.png) [@Caner](https://forum.babylonjs.com/u/Caner)\
**Post date:** [June 6, 2024, 4:02pm UTC](https://forum.babylonjs.com/t/incorrect-number-of-triangle-points-on-collision-testtriangle/51108/6 "2024-06-06T16:02:58Z")

</div>

@Tricotou’s answer works for me. I’m already doing some kind of validation on setting collisions, so I’ll just modify my logic as something like `mesh.checkCollisions = flag && !!mesh.getTotalIndices();`. I think the slight performance change will be worth the trade-off 🙂

Thanks a lot! Always a pleasure having you guys looking after me 😁

---

<div class="post-metadata">

**Author:** ![Tricotou](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/tricotou/32/5844_2.png) [@Tricotou](https://forum.babylonjs.com/u/Tricotou)\
**Post date:** [June 6, 2024, 4:08pm UTC](https://forum.babylonjs.com/t/incorrect-number-of-triangle-points-on-collision-testtriangle/51108/7 "2024-06-06T16:08:03Z")

</div>

> [@Deltakosh](#):
>
> If i was able to run that off thread, I would sign right now

Hold my beer 🍺

* * *

Ahah joking of course 😂 . Makes me think about this [awesome prez about JS main event loop](https://www.youtube.com/watch?v=cCOL7MC4Pl0). 6 years later, I’m still waiting for a JS version with real multithreading/multiprocessing 😁

> [@Caner](#):
>
> Thanks a lot!

Pleasure ! 🙂
