This is quite bizarre in my opinion. I create fixtures based on a fixtureDef. I use the libGDX version of Box2D. This is my code:
System.out.println("category bits of fixtureDef: " + fixtureDef.filter.categoryBits);
System.out.println("mask bits of fixtureDef: " + fixtureDef.filter.maskBits);
System.out.println("category bits of fixtureDef: " + fixtureDef_leftPropeller.filter.categoryBits);
System.out.println("mask bits of fixtureDef: " + fixtureDef_leftPropeller.filter.maskBits);
System.out.println("category bits of fixtureDef: " + fixtureDef_rightPropeller.filter.categoryBits);
System.out.println("mask bits of fixtureDef: " + fixtureDef_rightPropeller.filter.maskBits);
Body body = world.createBody(Res.bodyDef_dynamic);
fixture = body.createFixture(fixtureDef);
fixture_leftPropeller = body.createFixture(fixtureDef_leftPropeller);
fixture_rightPropeller = body.createFixture(fixtureDef_rightPropeller);
body.setTransform(pos.x * Drone2D.MPP, pos.y * Drone2D.MPP, 0);
body.setUserData(drone);
System.out.println(" ");
for (Fixture fix : body.getFixtureList()) {
System.out.println("category bits of fixture: " + fix.getFilterData().categoryBits);
System.out.println("mask bits of fixture: " + fix.getFilterData().maskBits);
}
The output of this code is:
category bits of fixtureDef: 2
mask bits of fixtureDef: 11
category bits of fixtureDef: 2
mask bits of fixtureDef: 11
category bits of fixtureDef: 2
mask bits of fixtureDef: 11
category bits of fixture: 4
mask bits of fixture: -1
category bits of fixture: 4
mask bits of fixture: -1
category bits of fixture: 4
mask bits of fixture: -1
WHAT? How can the filtering bits of my fixture not be the same of the fixtureDef they were created with?
I have also found this out: The mask that these fixtures get is instead the mask of the body that I have destroyed prior to creating these new fixtures.
Still, this should not happen.
Does anybody know what could lead to this sort of behavior?
Edit:
I found out that this filter scrambling phenomenon happens with every single body in my game.
My current work around is the following function, which seems to be sufficient:
public static void fixFixtureFilter(Fixture fixture, short maskBits, short categoryBits) {
Filter filter = fixture.getFilterData();
filter.maskBits = maskBits;
filter.categoryBits = categoryBits;
fixture.setFilterData(filter);
}
Still, something must be very wrong with my B2D world.