What meaning of partId as -1 in ContactAddedCallback?

Post Reply
donggas90
Posts: 17
Joined: Tue May 19, 2015 10:01 am

What meaning of partId as -1 in ContactAddedCallback?

Post by donggas90 »

I have a question about CompoundShape.
I wrote my own ContactAddedCallback for custom contact solve system.
Already known about partId the parameters those are mean child index of CompoundShape.

Code: Select all

bool ContactAdded(btManifoldPoint& cp, const btCollisionObject* colObj0, int partId0, int index0, const btCollisionObject* colObj1, int partId1, int index1)
{
	const btCollisionObject* Object0 = ((btCollisionObjectWrapper*)colObj0)->m_collisionObject;
	const btCollisionObject* Object1 = ((btCollisionObjectWrapper*)colObj1)->m_collisionObject;
	const btCollisionShape* Shape0 = Object0->getCollisionShape();
	const btCollisionShape* Shape1 = Object1->getCollisionShape();

	if (Shape0->getShapeType() == COMPOUND_SHAPE_PROXYTYPE)
	{
		Shape0 = ((btCompoundShape*)Shape0)->getChildShape(partId0);
	}
	if (Shape1->getShapeType() == COMPOUND_SHAPE_PROXYTYPE)
	{
		Shape1 = ((btCompoundShape*)Shape1)->getChildShape(partId1);
	}

        // Some works
        return true;
}
but in some cases, partId was -1 that is invalid index so Shape had been nullptr thus it occured access violation.
Why happened this situation?
And how can I fix it?
Thanks.
User avatar
drleviathan
Posts: 849
Joined: Tue Sep 30, 2014 6:03 pm
Location: San Francisco

Re: What meaning of partId as -1 in ContactAddedCallback?

Post by drleviathan »

I didn't know the answer so I started to look at the Bullet code to see if I could figure it out. I'm not 100% sure, but... it appears that partId is used to identify sub parts of individual shapes (i.e. triangles in a btGImpactShape) rather than child shapes in a btCompoundShape. So, I guess if all of child shapes were boxes and spheres (which have no sub parts) then the partId's would always be -1. Meanwhile, the index0 and index1 values identify the child shapes of btCompoundShapes.
donggas90
Posts: 17
Joined: Tue May 19, 2015 10:01 am

Re: What meaning of partId as -1 in ContactAddedCallback?

Post by donggas90 »

drleviathan wrote:I didn't know the answer so I started to look at the Bullet code to see if I could figure it out. I'm not 100% sure, but... it appears that partId is used to identify sub parts of individual shapes (i.e. triangles in a btGImpactShape) rather than child shapes in a btCompoundShape. So, I guess if all of child shapes were boxes and spheres (which have no sub parts) then the partId's would always be -1. Meanwhile, the index0 and index1 values identify the child shapes of btCompoundShapes.
Oh, I have mistaken partId for index. :lol: Thanks for answer!
Post Reply