harrison-lucas / bullet

Automatically exported from code.google.com/p/bullet
Other
0 stars 0 forks source link

Normalization of zero vector in SphereTriangleDetector::collide causing NaN values #676

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
From line 102 in SphereTriangleDetector.cpp in the latest bullet trunk:

btVector3 normal = (vertices[1]-vertices[0]).cross(vertices[2]-vertices[0]);
// If normal is btVector3(0,0,0), this call turns normal into NaN values
normal.normalize();

Changing it to this fixes it:

btVector3 normal = (vertices[1]-vertices[0]).cross(vertices[2]-vertices[0]);
if (normal != btVector3(0,0,0))
    normal.normalize();

Alternatively, I noticed Bullet uses something like this in other places:

if (normal.length2() > btScalar(0.0001))

It's important to note that I only received NaN values on iOS 6 (ARMv7) in 
release mode. It doesn't happen in debug mode on iOS, or in either release and 
debug on OSX.

Original issue reported on code.google.com by m...@danielsefton.com on 25 Nov 2012 at 7:55

GoogleCodeExporter commented 9 years ago
Do you have the triangle mesh that you are feeding into Bullet?

Are there degenerate/zero-area triangles?

Original comment by erwin.coumans on 25 Nov 2012 at 8:07

GoogleCodeExporter commented 9 years ago
There could be, it's a capsule shape generated at runtime by Ogre Procedural. 
This consistently happens when the sphere collides with one of the ends of the 
shape. Are you suggesting that Bullet shouldn't be to blame, and for it to 
remain on the assumption you don't feed it "degenerate/zero-area" triangles? I 
guess I could try asking the developer of Ogre Procedural to take a look at it.

Original comment by m...@danielsefton.com on 25 Nov 2012 at 8:17

GoogleCodeExporter commented 9 years ago

It would be best to add some asserts in Bullet, so we can catch the problem 
earlier. We should have some 'warning' mechanism in Bullet, rather than asserts 
to make it more user friendly. I'll have to think about the best solution.

At the same time, it would be good to fix the problem at the origin (Ogre 
Prodedural).

Original comment by erwin.coumans on 25 Nov 2012 at 8:28

GoogleCodeExporter commented 9 years ago
Ok, agreed. It took a few hours of print log debugging through Bullet to find 
this, a warning/assert would have saved that. In the meantime I'll leave that 
zero check in on the basis of "it doesn't crash, ship it". Thanks for the quick 
response!

Original comment by m...@danielsefton.com on 25 Nov 2012 at 8:47

GoogleCodeExporter commented 9 years ago
See https://github.com/bulletphysics/bullet3/issues/110

Original comment by erwin.coumans on 30 Mar 2014 at 7:19