btSphereSphereCollisionAlgorithm division by 0

Post Reply
SeanTasker
Posts: 2
Joined: Tue Nov 13, 2007 1:21 am

btSphereSphereCollisionAlgorithm division by 0

Post by SeanTasker »

Hi Erwin,
While working on a project we have found that the btSphereSphereCollisionAlgorithm causes a crash when two spheres are in the same position.

I've patched the following code to include a check

Code: Select all

	btVector3 diff = col0->getWorldTransform().getOrigin()-  col1->getWorldTransform().getOrigin();
	btScalar len = diff.length();
	btScalar radius0 = sphere0->getRadius();
	btScalar radius1 = sphere1->getRadius();
to

Code: Select all

	btVector3 diff = col0->getWorldTransform().getOrigin()-  col1->getWorldTransform().getOrigin();
	btScalar len = diff.length();
	if(len==0.0f)
		return;
	btScalar radius0 = sphere0->getRadius();
	btScalar radius1 = sphere1->getRadius();
I realise that this is something that doesn't tend to happen much and that we should be spawning our objects in different places. In the rare even that this happens the above patch fixes it :)

Thank you a million for bullet it is absolutely awesome! :)
-Sean Tasker
User avatar
Erwin Coumans
Site Admin
Posts: 4232
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA
Contact:

Re: btSphereSphereCollisionAlgorithm division by 0

Post by Erwin Coumans »

Thanks for the report, this will be fixed!

Erwin
User avatar
Erwin Coumans
Site Admin
Posts: 4232
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA
Contact:

Re: btSphereSphereCollisionAlgorithm division by 0

Post by Erwin Coumans »

It has been fixed, slightly different: it will report a penetration, with an arbitrary separating normal (1,0,0).

Thanks a lot for the feedback,
Erwin
Post Reply