Box2D Forums

It is currently Sun May 19, 2013 4:49 am

All times are UTC - 8 hours [ DST ]




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: Bug with edges?
PostPosted: Thu Sep 29, 2011 5:12 am 
Offline

Joined: Thu Sep 29, 2011 4:41 am
Posts: 3
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!


Top
 Profile  
 
 Post subject: Re: Bug with edges?
PostPosted: Thu Sep 29, 2011 8:53 am 
Offline
Site Admin

Joined: Thu Sep 06, 2007 12:34 am
Posts: 2931
Please dump out a testbed file using b2World::Dump().


Top
 Profile  
 
 Post subject: Re: Bug with edges?
PostPosted: Thu Sep 29, 2011 11:33 am 
Offline

Joined: Thu Sep 29, 2011 4:41 am
Posts: 3
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!


Top
 Profile  
 
 Post subject: Re: Bug with edges?
PostPosted: Mon Oct 03, 2011 3:58 am 
Offline

Joined: Thu Sep 29, 2011 4:41 am
Posts: 3
But I think this is not a good excuse to return NaN. What do you think?


Top
 Profile  
 
 Post subject: Re: Bug with edges?
PostPosted: Mon Oct 03, 2011 9:27 pm 
Offline
Site Admin

Joined: Thu Sep 06, 2007 12:34 am
Posts: 2931
No, I don't think NaNs are good. If you want to attach a dump file, I'll take a look.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC - 8 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group