Page 1 of 3

New issue with gContactAddedCallback in Bullet 2.75

Posted: Fri Sep 11, 2009 10:07 pm
by rknoesel
First of all, thanks for getting v2.75 out the door, a great accomplishment!!

We just upgraded from v2.75 RC3 to the release version and ran into an issue with gContactAddedCallback:

Between RC3 and release, a change was made in btManifoldResult.cpp which breaks the partId and index parameters for gContactAddedCallback when obj0 and obj1 are swapped. The RC3 version handled the swap in the two lines preceding the gContactAddedCallback call. The final version now also handles the swap a few lines above, resulting in a doubly-swapped call (if that makes sense :)).

The fix was to replace

Code: Select all

		(*gContactAddedCallback)(m_manifoldPtr->getContactPoint(insertIndex),obj0,newPt.m_partId0,newPt.m_index0,obj1,newPt.m_partId1,newPt.m_index1);
with

Code: Select all

		(*gContactAddedCallback)(m_manifoldPtr->getContactPoint(insertIndex),obj0,m_partId0,m_index0,obj1,m_partId1,m_index1);
Ralf Knoesel
Vector Unit Inc

Re: New issue with gContactAddedCallback in Bullet 2.75

Posted: Fri Sep 11, 2009 10:40 pm
by Erwin Coumans
It might have slipped through, this swapping is confusing and error prone, did you assume m_index0 is swapped or not?

There are 3 main use cases of the part ID, did you check all 3 with the fix?

for btCompoundShape in btCompoundCollisionAlgorithm.cpp:

Code: Select all

	///detect swapping case
	if (m_resultOut->getBody0Internal() == m_compoundColObj)
	{
		m_resultOut->setShapeIdentifiersA(-1,index);
	} else
	{
		m_resultOut->setShapeIdentifiersB(-1,index);
	}
for btBvhTriangleMeshShape concave collision btConvexConcaveCollisionAlgorithm.cpp:

Code: Select all

	m_resultOut->setShapeIdentifiersB(partId,triangleIndex);
and btGImpactShape in btGImpactCollisionAlgorithm.cpp

Code: Select all

	m_resultOut->setShapeIdentifiersA(m_part0,m_triface0);
	m_resultOut->setShapeIdentifiersB(m_part1,m_triface1);
Thanks for the feedback,
Erwin

Re: New issue with gContactAddedCallback in Bullet 2.75

Posted: Fri Sep 11, 2009 11:32 pm
by rknoesel
There are 3 main use cases of the part ID, did you check all 3 with the fix?
The change I made is localized to only change the parameters passed to the gContactAddedCallback, nothing else. I simply changed the parameters back to what they were in RC3, which solves our issue. I did not take a deeper look to see if there were any other issues outside the gContactAddedCallback functionality.
It might have slipped through, this swapping is confusing and error prone, did you assume m_index0 is swapped or not?
The code from RC3 assumes that m_index0 is not swapped, but it swaps m_body0 and m_body1 if necessary just before calling gContactAddedCallback.
Thanks for the feedback,
No problem!!! Thanks for making our project possible!

Ralf

Re: New issue with gContactAddedCallback in Bullet 2.75

Posted: Wed Oct 07, 2009 5:26 pm
by rrck
I also have issue in 2.75 release with swapped index and part id's.

When CompoundShape and TriangleMeshShape collides, in gContactAddedCallback id's and indexe's are swapped.

After trying rknoesel suggested solution everything was correct.

Re: New issue with gContactAddedCallback in Bullet 2.75

Posted: Wed Oct 07, 2009 7:11 pm
by rrck
After closer look I found another strange issue. If understand correctly for trimesh shape both index and part id is initialized and compound shape have partId initialized, but when compound and tri mesh shapes collides in gContactAddedCallback only one object partId and index are initialized other object partId and index is setted to -1.

Re: New issue with gContactAddedCallback in Bullet 2.75

Posted: Sun Dec 06, 2009 10:16 pm
by sparkprime
I think I may be hitting this problem now. Any conclusion?

Re: New issue with gContactAddedCallback in Bullet 2.75

Posted: Sun Dec 06, 2009 10:35 pm
by sparkprime
I see a part id of -1 on my compound mesh. Seems to happen all the time but I only notice when the array bounds error actually touches memory without 0 in it. I've hacked around this for now by setting it to 0 if it's -1. This is with bleeding edge SVN.

Re: New issue with gContactAddedCallback in Bullet 2.75

Posted: Mon Dec 07, 2009 4:04 am
by sparkprime
I also see a lot of invalid face ids with the btBvhTriangleShape -- the face id is complete garbage so this looks like memory corruption of some kind. It only occurs when there are a lot of objects in the world. Doesn't seem to matter what those objects are. However I always use btBvhTriangleMesh for the ground and all the other meshes are structures of hulls and primitives in a btCompoundShape each.

Re: New issue with gContactAddedCallback in Bullet 2.75

Posted: Mon Dec 07, 2009 11:54 am
by rrck
I have filled new issue(316) in google.code. Issue includes small patch which fixed, this problem for me. But it was only tested for trimesh vs compunds, and I'am not 100% sure that this solutions is right :).

Re: New issue with gContactAddedCallback in Bullet 2.75

Posted: Mon Dec 07, 2009 11:06 pm
by sparkprime
Thanks, I applied that patch and it seems to have solved my index problem, where the indexes were completely scrambled.

However for the part id being -1, it made no difference at all... weird

Re: New issue with gContactAddedCallback in Bullet 2.75

Posted: Wed Dec 09, 2009 7:08 pm
by rrck
I think that partId for compounds are always set to -1.

Re: New issue with gContactAddedCallback in Bullet 2.75

Posted: Wed Dec 09, 2009 10:26 pm
by Erwin Coumans
rrck wrote:I have filled new issue(316) in google.code. Issue includes small patch which fixed, this problem for me. But it was only tested for trimesh vs compunds, and I'am not 100% sure that this solutions is right :).
Sounds good. I'm going to test it and apply this patch.

Thanks for the reports and testing everyone!
Erwin

Re: New issue with gContactAddedCallback in Bullet 2.75

Posted: Thu Dec 10, 2009 6:26 am
by sparkprime
So partId is not yet implemented? What is it for if not for compounds? I can probably calculated it in the callback just by iterating through the members of the compound looking for the shape in question, but that's a bit of a drag.

Re: New issue with gContactAddedCallback in Bullet 2.75

Posted: Sat Dec 12, 2009 12:33 pm
by rrck
indexId represents child id of compound shape. As I know partId is used for tri meshes to point which triangles array is collided.

Re: New issue with gContactAddedCallback in Bullet 2.75

Posted: Sun Dec 13, 2009 3:53 am
by sparkprime
I thought it was the other way round. In fact, why is there two params in the first place?