b2ContactListener and points of contact.

I'm having some weirdness with the b2ContactListener, but it is likely that I just don't understand what is supposed to be happening. So let me describe what is happening:

I have a class, CContactManager, which inherits from b2ContactListener and an instance of this class gets set as the listener, mWorld->SetListener(gContactManager). My level is fairly complicated with some thing near 80 to 100 shapes being created just for the level. I have one dynamic body in the world, the character, and it is simply a box and I have the character assigned to the userdata of the body.

In CContactManager::Add(...) I am getting the bodies from the shapes and checking to see if the user data is my character, when it is I am doing some game logic. Similarly for Remove(...). The issue is that I get say 4 or 5 calls to Add in one frame causing my game logic to be called 4 or 5 times. Thing is, I don't see a way to identify the b2ContactPoints, so I'm not sure if I'm getting 4 or 5 different points or 4 or 5 calls with the same point. I've tried point->id.key, but in this case I do end up with 4 or 5 with the same 'keys'. And then in the Remove call I never see the key(s) that I see from Add, for example in Add I print out the key and its '16843009' which gets printed 4 or 5 times. The key that gets printed in remove is '3435973836' which gets printed 4 or 5 times as well.

So is this expected behavior, or have I misunderstood something somewhere?
This is probably a bug. I'll look into it.
This is fixed in the current SVN version.
Umm...Do you mind expounding that a little?
The contact id was not being initialized. You can now uniquely identify a contact using the two shapes and the contact id (key). You should use the user data to identify your shapes.

There may be no need to use the contact id. You could just use the user data on the shapes to identify the contacts. You can have up to two contact points per shape pair. If one of the shapes is a circle, you can only get one contact point per shape pair.
Erin Catto wrote:
The contact id was not being initialized. You can now uniquely identify a contact using the two shapes and the contact id (key). You should use the user data to identify your shapes.

There may be no need to use the contact id. You could just use the user data on the shapes to identify the contacts. You can have up to two contact points per shape pair. If one of the shapes is a circle, you can only get one contact point per shape pair.



I think that circles are still having this problem, FYI

Also, any idea what might be causing me to get the call to add 4 times with one id and then remove 4 times with the same id (when I jump or pick the object up with a mouse joint)?
Are you getting the same id and the same shape pair? The id is not enough on its own.

You can get some repeated calls due to continuous physics, which will subdivide the time step. This is more pronounced if you have elastic collisions (restitution > 0).

I did miss the polygon vs circle id. I'll fix that tonight.
um... 😳 ... It appears that I was creating my world 4x due to some bad designer data.

Bad designer, No doughnut 😈!

Original thread: https://box2d.org/forum/viewtopic.php?t=372