New issue with gContactAddedCallback in Bullet 2.75

rknoesel
Posts: 17
Joined: Wed Feb 25, 2009 2:18 am

New issue with gContactAddedCallback in Bullet 2.75

Post by rknoesel » Fri Sep 11, 2009 10:07 pm

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

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

Re: New issue with gContactAddedCallback in Bullet 2.75

Post by Erwin Coumans » Fri Sep 11, 2009 10:40 pm

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

rknoesel
Posts: 17
Joined: Wed Feb 25, 2009 2:18 am

Re: New issue with gContactAddedCallback in Bullet 2.75

Post by rknoesel » Fri Sep 11, 2009 11:32 pm

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

rrck
Posts: 26
Joined: Mon Sep 21, 2009 7:30 am

Re: New issue with gContactAddedCallback in Bullet 2.75

Post by rrck » Wed Oct 07, 2009 5:26 pm

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.

rrck
Posts: 26
Joined: Mon Sep 21, 2009 7:30 am

Re: New issue with gContactAddedCallback in Bullet 2.75

Post by rrck » Wed Oct 07, 2009 7:11 pm

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.

sparkprime
Posts: 508
Joined: Fri May 30, 2008 2:51 am
Location: Ossining, New York
Contact:

Re: New issue with gContactAddedCallback in Bullet 2.75

Post by sparkprime » Sun Dec 06, 2009 10:16 pm

I think I may be hitting this problem now. Any conclusion?

sparkprime
Posts: 508
Joined: Fri May 30, 2008 2:51 am
Location: Ossining, New York
Contact:

Re: New issue with gContactAddedCallback in Bullet 2.75

Post by sparkprime » Sun Dec 06, 2009 10:35 pm

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.

sparkprime
Posts: 508
Joined: Fri May 30, 2008 2:51 am
Location: Ossining, New York
Contact:

Re: New issue with gContactAddedCallback in Bullet 2.75

Post by sparkprime » Mon Dec 07, 2009 4:04 am

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.

rrck
Posts: 26
Joined: Mon Sep 21, 2009 7:30 am

Re: New issue with gContactAddedCallback in Bullet 2.75

Post by rrck » Mon Dec 07, 2009 11:54 am

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 :).

sparkprime
Posts: 508
Joined: Fri May 30, 2008 2:51 am
Location: Ossining, New York
Contact:

Re: New issue with gContactAddedCallback in Bullet 2.75

Post by sparkprime » Mon Dec 07, 2009 11:06 pm

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

rrck
Posts: 26
Joined: Mon Sep 21, 2009 7:30 am

Re: New issue with gContactAddedCallback in Bullet 2.75

Post by rrck » Wed Dec 09, 2009 7:08 pm

I think that partId for compounds are always set to -1.

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

Re: New issue with gContactAddedCallback in Bullet 2.75

Post by Erwin Coumans » Wed Dec 09, 2009 10:26 pm

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

sparkprime
Posts: 508
Joined: Fri May 30, 2008 2:51 am
Location: Ossining, New York
Contact:

Re: New issue with gContactAddedCallback in Bullet 2.75

Post by sparkprime » Thu Dec 10, 2009 6:26 am

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.

rrck
Posts: 26
Joined: Mon Sep 21, 2009 7:30 am

Re: New issue with gContactAddedCallback in Bullet 2.75

Post by rrck » Sat Dec 12, 2009 12:33 pm

indexId represents child id of compound shape. As I know partId is used for tri meshes to point which triangles array is collided.

sparkprime
Posts: 508
Joined: Fri May 30, 2008 2:51 am
Location: Ossining, New York
Contact:

Re: New issue with gContactAddedCallback in Bullet 2.75

Post by sparkprime » Sun Dec 13, 2009 3:53 am

I thought it was the other way round. In fact, why is there two params in the first place?

Post Reply