# Why is the MaskBit maxed out

Hi there for some reason the maskbit of my b2FixtureDef is being maxxed out and im not sure why

Here is the declaration of the items that are used in the game

enum PhysicBits {
PB_NONE = 0x0000,
PB_PLAYER = 0x0001,
PB_PLATFORM = 0x0002
};


Basically what i want is the player to run along a surface is not slow down (i set platform & player friction to 0.0f)

I then setup my Contact Listener to print out the connections (currently only have 1 platform and 1 player)

Player Fixture Def

b2FixtureDef fixtureDef;
fixtureDef.shape = &groundBox;
fixtureDef.density = 1.0f;
fixtureDef.friction = 0.0f;
fixtureDef.filter.categoryBits = PB_PLAYER;


Platform Fixture Def

b2FixtureDef fixtureDef;
fixtureDef.shape = &groundBox;
fixtureDef.density = 1.0f;
fixtureDef.friction = 0.0f;
fixtureDef.filter.categoryBits = PB_PLATFORM;


Now correct me if im wrong but these are saying the following:

• Player Collides with Platform
• Platform Collides with Player

Here is the printout of the fixtures colliding with each other

********    <-- Indicates new Contact
Platform
ContactA: 2
------
Player
ContactB: 1
********    <-- Indicates new Contact
Platform
ContactA: 2
------
Player
ContactB: 1
********    <-- Indicates new Contact
Platform
ContactA: 1
------
Player
ContactB: 1


Here is where i am confused. On the second & third contact the player maskBit is set to 65535 when it should be 2 and there are 3 contacts when i am sure at most there should only be 2.

I've been trying to figure this out for hours and i can't understand why it is doing this. I would be very grateful is someone could shine some light on this for me

UPDATE: **I printed out the class of the contacting objects. For some reason it seems to do the following:

First Contact: Correct Result.

Second Contact: Player b2Fixture Obtains a new maskBit.

Third Contact: Platform b2Fixture appears to be set to the same as the Player b2Fixture. It would seem I have a memory race condition i think**

• Are you sure you're not getting some other collision in there? Is there really only a platform and a player in your world? – bummzack Jul 16 '12 at 9:27
• yep i only add the two items into my world – CStreel Jul 16 '12 at 9:29
• also if it helps im using cocos2d+box2d – CStreel Jul 16 '12 at 9:29

Ok so it seems I've figured it out.

Firstly, the multiple BeginContact Calls:

From what i can gather this is from the fact that i was checking against two Edges Colliding, and during the velocity steps of Box2d (which i had set to 8) it kept pushing the Edges apart which would cause them to overlap again and fire off another BeginContact.

It resolved my multiple BeginContact calls by switching the player & platform to Boxes (with out custom edges, using setAsBox).

I don't know if it is a Cocos2d+Box2d related issue, but i was checking the wrong filterData.

What i was doing:

contact->GetFixtureA()->GetFilterData();


What i am now doing:

contact->GetFixtureA()->GetBody()->GetFixtureList()->GetFilterData();


Now i don't know why the filterData is stored twice in the b2Fixture object, but it seems a little redundant to me. Or if i am even supposed to use the b2Body filterData.

But my collision detection works perfectly now