Bug with edges?

Hi!

I think I found a bug in Box2D. I was using 2.1.2 versión, I updated it to 2.2.1 and the bug continues there.

I will try to cut the specific code by copying them from my big program. I apologize if anything is missing.


First I make a box to limit a 'rectangular world' with 4 edges:

Code:
void
_CreateFrame()
{
   b2BodyDef       groundBodyDef;
   b2EdgeShape      groundEdge;
   b2FixtureDef   boxShapeDef;
   float         width, height;
   float         margin;

   margin = 32;

   width  = (IDevice::GetWindowManager()->GetWidth()  + margin) * gPixelsToMeters;
   height = (IDevice::GetWindowManager()->GetHeight() + margin) * gPixelsToMeters;

   groundBodyDef.position.Set(0, 0);
   mpGroundBody = mPhisicWorld.CreateBody(&groundBodyDef);

   boxShapeDef.shape = &groundEdge;

   margin *= -gPixelsToMeters;

   groundEdge.Set(b2Vec2(margin, margin), b2Vec2(width, margin));
   mpGroundBody->CreateFixture(&boxShapeDef);

   groundEdge.Set(b2Vec2(margin, margin), b2Vec2(margin, width));
   mpGroundBody->CreateFixture(&boxShapeDef);

   groundEdge.Set(b2Vec2(margin, height), b2Vec2(width, height));
   mpGroundBody->CreateFixture(&boxShapeDef);

   groundEdge.Set(b2Vec2(width, height), b2Vec2(width, margin));
   mpGroundBody->CreateFixture(&boxShapeDef);
}


Then I create a ball:

Code:
void
_CreateBall(b2Vec2 _position;)
{
   b2BodyDef      ballBodyDef;
   b2CircleShape   circle;
   b2FixtureDef   ballShapeDef;

   ballBodyDef.type = b2_dynamicBody;

   ballShapeDef.shape       = &circle;
   ballShapeDef.density     = 2.0f;
   ballShapeDef.friction    = 0.4f;
   ballShapeDef.restitution = 0.2f;

   circle.m_radius = 128;
   
   mpBall = mPhisicWorld.CreateBody(&ballBodyDef);
   mpBall->CreateFixture(&ballShapeDef);
   
   mpBall->SetTransform(position, angle);
}


BUG: If the ball hits the top or the left edge my program crash because I'm getting NaN in the position and rotation of the ball.

Note that I initialize the world without gravity and update the world every frame in this way:

Code:
// Init
mPhisicWorld(b2Vec2(0, 0))


Code:
// on every frame
mPhisicWorld.Step(1.0f/30.0f, 10, 10);


Furthermore, if I put margin = 0 in the function _CreateFrame all works fine.

Could someone reproduce the bug, please?
Any suggestions for prevent it?

Thanks!
Please dump out a testbed file using b2World::Dump().
Oops! I found the problem. I was aplying a force outside the object.

Code:
mpBall->ApplyForce(time * b2Vec2(fx, fy), position);


position was in pixels, not in Box2D units.

I apologize!
But I think this is not a good excuse to return NaN. What do you think?
No, I don't think NaNs are good. If you want to attach a dump file, I'll take a look.

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