btPersistentManifold::getNumContacts always returns zero

Post Reply
s_kohan
Posts: 5
Joined: Tue Apr 02, 2019 9:11 am

btPersistentManifold::getNumContacts always returns zero

Post by s_kohan »

I want to get access to the contact point details for a collision. The problem is, whenever I try to get the number of contacts from a manifold, via btPersistentManifold::getNumContacts, the result is always zero. Here's how I'm getting the contacts:

Code: Select all

  
        // these methods are part of a C wrapper so I can use bullet using the C FFI

	int btDynamicsWorldGetCollisionCount(btDynamicsWorldRef* world) {
		return ((btDynamicsWorld*)world)->getDispatcher()->getNumManifolds();
	}
	
	btContact btDynamicsWorldGetCollision(btDynamicsWorldRef* world, int index) {
	
		btPersistentManifold* contactManifold = ((btDynamicsWorld*)world)->getDispatcher()->getManifoldByIndexInternal(index);
		
		btContact contact; // this is a struct defined to expose contact info to this C wrapper
		contact.objectA = contactManifold->getBody0()->getUserPointer();
		contact.objectB = contactManifold->getBody1()->getUserPointer();
		contact.manifoldRef = (btContactManifoldRef*)contactManifold;
		return contact;
		
	}
	
     int btContactManifordGetContactCount(btContactManifoldRef* manifold) {
        btPersistentManifold* contactManifold = (btPersistentManifold*) manifold;
        int count = contactManifold->getNumContacts();
        return count;
    }

The strange thing is, when I debug, I can see that there are 4 btManifoldPoint records inside contactManifold->m_pointCache. What am I missing here?
User avatar
drleviathan
Posts: 699
Joined: Tue Sep 30, 2014 6:03 pm
Location: San Francisco

Re: btPersistentManifold::getNumContacts always returns zero

Post by drleviathan »

I would like to help, however I don't have any good hypothesises. I looked at some working code that harvests contacts details from the contact manifolds and AFAICT your code should work. Perhaps you could supply enough source to actually build and reproduce your problem?
s_kohan
Posts: 5
Joined: Tue Apr 02, 2019 9:11 am

Re: btPersistentManifold::getNumContacts always returns zero

Post by s_kohan »

Thank you, I actually ended up solving the problem myself. It turns out the problem was a false assumption I had about the contact manifolds: I thought they would only be created when there were already points of contact, but it turns out those "collisions" are already registered when the bodies are just close (broad-phase detection I think?) - so I just had to make my collision handling logic a bit smarter and wait until the collision manifolds already had contacts before handling it.
acu192
Posts: 6
Joined: Thu Jan 28, 2021 12:23 am

Re: btPersistentManifold::getNumContacts always returns zero

Post by acu192 »

Yep, I'm seeing the same behavior as @s_kohan. Even if there is a btPersistentManifold, you still have to check getNumContacts() > 0 to actually know if the collision is for-realz.
Post Reply