Serious bug in btOptimizedBvh.cpp

Post Reply
reltham
Posts: 66
Joined: Fri Oct 12, 2007 6:28 pm
Location: San Diego

Serious bug in btOptimizedBvh.cpp

Post by reltham »

This is added to the google code issue tracker as well.

These lines:
807 rayDirection[0] = btScalar(1.0) / rayDirection[0];
808 rayDirection[1] = btScalar(1.0) / rayDirection[1];
809 rayDirection[2] = btScalar(1.0) / rayDirection[2];

Were changed to this:
807 rayDirection[0] = rayDirection[0] == btScalar(0.0) ? btScalar(1.0) : btScalar(1.0) / rayDirection[0];
808 rayDirection[1] = rayDirection[1] == btScalar(0.0) ? btScalar(1.0) : btScalar(1.0) / rayDirection[1];
809 rayDirection[2] = rayDirection[2] == btScalar(0.0) ? btScalar(1.0) : btScalar(1.0) / rayDirection[2];

This code is invalied for any ray direction that is along an axis. (for example (0, -1, 0), it ends up changing the ray direction badly.
This causes many raytest or convexsweeptest to fail (miss or report an incorrect hit).

In my code I changed the lines to this:
807 rayDirection[0] = rayDirection[0] == btScalar(0.0) ? btScalar(9999999.0) : btScalar(1.0) / rayDirection[0];
808 rayDirection[1] = rayDirection[1] == btScalar(0.0) ? btScalar(9999999.0) : btScalar(1.0) / rayDirection[1];
809 rayDirection[2] = rayDirection[2] == btScalar(0.0) ? btScalar(9999999.0) : btScalar(1.0) / rayDirection[2];

And this resolved the problem for me. Perhaps there is another way to accomplish what is desired that would be more correct than my solution?
Anyway, can this change be made in the meantime?
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA
Contact:

Re: Serious bug in btOptimizedBvh.cpp

Post by Erwin Coumans »

Thanks for reporting, this problem was introduced just before 2.70 release to get rid of some FPU exceptions.

We will fix it asap,
Erwin
Post Reply