A bug? (Passing through a static body)

Ok, I'm not quite sure exactly what triggers it, but it seems like one polygon can suddenly be thrown through another. As I have seem it, it happens only when the are slightly askew to each other, and only when one is static and the non-static is traveling in either a positive X or positive Y direction.


This small program reproduces the problem om my machine (using Box2D 1.4.2) - Not sure whether the same effect happens elsewhere yet. It should create a dynamic box at y = 27.65 [could be less, but this limits the output] and a larger static box at y = 30. The static box should be wide enough so the dynamic one should hit it...

Just for completeness, the interesting part of the output is attached below the program.


#include <Box2D.h>
#include <cstdlib>

b2Body* create_movable(b2World& world)
{
b2PolyDef box;
box.vertexCount = 4;
box.vertices[0].Set(2.0, 1.2);
box.vertices[1].Set(-2.0, 1.2);
box.vertices[2].Set(-2.0, -1.2);
box.vertices[3].Set(2.0, -1.2);

box.density = 1;
box.friction = 0.15f;
box.restitution = 0.6;

b2BodyDef body;
body.position.Set(45, 27.65);
body.allowSleep = false;
body.rotation = 330.0f / 180.0f * M_PI;
body.AddShape(&box);

return world.CreateBody(&body);
}

b2Body* create_static(b2World& world)
{
b2PolyDef box;
box.vertexCount = 4;
box.vertices[0].Set(20.1, 0.22);
box.vertices[1].Set(-20.03, 0.23);
box.vertices[2].Set(-20.05, -0.21);
box.vertices[3].Set(20.01, -0.23);

box.density = 0;
box.friction = 0.5;
box.restitution = 0.5;
b2BodyDef body;
body.position.Set(32, 30);
body.AddShape(&box);

return world.CreateBody(&body);
}

int main ( int argc, char** argv )
{
b2AABB worldAABB = {b2Vec2(0, 0), b2Vec2(64, 48)};
b2World world(worldAABB, b2Vec2(0.0f, 0.005f), false);

b2Body* mov = create_movable(world);
b2Body* stat = create_static(world);

bool done = false;
while (!done)
{
if (mov->GetCenterPosition().y > 31.5) exit(0);
printf("(%f, %f, %f)\n", mov->GetCenterPosition().x, mov->GetCenterPosition().y, mov->GetRotation());

world.Step(0.01, 10);
}

return 0;
}


// interesting part of the output
// x, y, angle
// probably more than a hundre lines above this
(45.000000, 27.729099, 5.759587)
(45.000000, 27.729382, 5.759587)
(45.000000, 27.729664, 5.759587)
(45.000000, 27.729946, 5.759587)
(45.000114, 28.064529, 5.775726)
(45.000191, 28.393602, 5.792654)
(45.000267, 28.717144, 5.810221)
(45.000343, 29.035154, 5.828268)
(45.000420, 29.347729, 5.846627)
(45.000496, 29.655041, 5.865135)
(45.000572, 29.957279, 5.883638)
(45.000648, 30.254730, 5.901997)
(45.000717, 30.538118, 5.932713)
(45.000755, 30.771885, 6.022929)
(45.000793, 30.981495, 6.117511)
(45.000832, 31.175991, 6.207919)
(45.000866, 31.342186, 6.279333)
(45.000866, 31.398182, 6.283381)
(45.000866, 31.412209, 6.283097)
(45.000866, 31.415705, 6.282977)
(45.000866, 31.416576, 6.282943)
(45.000866, 31.416868, 6.282943)
(45.000866, 31.417160, 6.282943)
(45.000866, 31.417452, 6.282943)
Thanks for the thorough bug report.

I reproduced the bug and found that the polygon collider is picking the wrong contact normal due to an incorrect local search.

I will fix this bug for v2.0. That may be a couple weeks. In the meantime, you can avoid this bug by using shorter, fatter polygons.
Wow, this is bizarre - I just noticed what I suspect from your description might be the exact same bug while I was testing the convex decomposition code, and logged on just now to report it. See if you think this is the same thing or not, it sounds right from your explanation.

The setup:

Image

If you rotate the upper "E" so that it goes flush against the left edge of the lower one, they "pop" away from each other so that they are no longer interlocking, the moment that they touch. This happens whether one of the bodies is static or not. I assumed that this was caused by the fact that I had multiple shapes on the same body, but if it's happening elsewhere, too, then I guess that's wrong. BTW, I checked, and this happens regardless of whether the shapes are generated from the decomposition algorithm or not. The absolute scale of the shapes doesn't seem to matter, either.

If you don't think this is the same thing, I can upload code for a test case, but it sounds pretty similar so I won't for now. I've noticed a few other strange interactions when these things touch, but I suspect it might all stem from this bug - I'll upload a demo soon that you can play with and see for yourself.
Is the upper E is dragged to the left, through the leftmost leg of the lower E? If so, it looks to me as this is the same bug...
I would be suprised if this is the same bug, because the shapes have more balanced features.

Over the next couple days I'll disable CCD and fix the first bug, then we can try your case (the Es).
I suspect this is the same bug from which demo is suffering.

Here's the test code. http://pastebin.com/f40c4d8bd (version of Box2D was 1.4.2.)

The box penetrates (weirdly) the thin static wall.

Image
Thanks for test case. This will help me verify my fix. I'll have 1.4.3 out this weekend.
Would anyone care to test the fix in SVN? I tested the cases submitted by demo and gummikana.

1.4.3 should go out by tomorrow night.
I'll give it a spin later today.
I tested with the SVN version and while it works much better than the previous version, there is still something odd about the collision.

Here's a testcase that shows the oddity.
http://pastebin.com/m6cae6163

The box penetrates the left wall at the bottom of the U shape.

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