Box2D Forums

 It is currently Sat May 18, 2013 10:27 pm

 All times are UTC - 8 hours [ DST ]

 Page 2 of 3 [ 22 posts ] Go to page Previous  1, 2, 3  Next
 Print view Previous topic | Next topic
Author Message
 Post subject: Re: Box2D Freeze / HangPosted: Sun Mar 07, 2010 1:56 pm

Joined: Wed Sep 09, 2009 6:29 pm
Posts: 18
Alright well good luck with your hang. Mine is definitively caused by the Box2D step function, but I might be doing something stupid before the call. Anyone feel like they could explain to me what the above For loop is? Thanks!

Top

 Post subject: Re: Box2D Freeze / HangPosted: Mon Mar 08, 2010 1:47 pm

Joined: Mon Jan 07, 2008 10:51 am
Posts: 1911
I have looked over this code many times. I will not be able to fix any problems in it without a reproducible test case.

The code is (gasp) calculating time of impact for two moving shapes, iterating using numerical techniques. Reaching 50 means it is not converging at all (it rarely goes above 5 iterations in normal use).

Top

 Post subject: Re: Box2D Freeze / HangPosted: Mon Mar 08, 2010 1:55 pm

Joined: Wed Sep 09, 2009 6:29 pm
Posts: 18
Makes sense, I will try to give you a good repro

In the meantime, do post if you can think of potential situations that could cause this loop to not converge!

Top

 Post subject: Re: Box2D Freeze / HangPosted: Tue Mar 09, 2010 3:18 pm

Joined: Wed Sep 09, 2009 6:29 pm
Posts: 18
Hi again,

I think I've found the fix here. The problem for the SolveTOI function is that the first fixture's body position X and Y values are NaN. I can imagine how this prevent SolveTOI from converging

Now the question became: what is setting that body's position to NaN? So I looked into all the instances where b2Body:m_xf.position was changing, and found that the position is changed within the step() as well. Here's the callstack:

Code:
at Box2D.Dynamics::b2Body/http://www.box2d.org/ns/b2internal::SynchronizeTransform()[C:\Users\Swah\flash\com\Box2D\Dynamics\b2Body.as:1297]
at Box2D.Dynamics.Contacts::b2ContactSolver/SolvePositionConstraints()[C:\Users\Swah\flash\com\Box2D\Dynamics\Contacts\b2ContactSolver.as:906]
at Box2D.Dynamics::b2Island/Solve()[C:\Users\Swah\flash\com\Box2D\Dynamics\b2Island.as:280]
at Box2D.Dynamics::b2World/http://www.box2d.org/ns/b2internal::Solve()[C:\Users\Swah\flash\com\Box2D\Dynamics\b2World.as:1083]

Turns out m_sweep.c values were set to NaN.

I started to look everywhere for b2Vec2 classes being set to NaN, and I realized I was multiplying the position of a mouseJoint attached to that body by a NaN value (1 divided by 0). So! My understanding is that by setting the b2MouseJoint:SetTarget to a NaN vector, I caused this hang.

I'm not sure where, but it sounds like we would want to add an assert somewhere to make sure no one hits that hang again. The SolveTOI part is the part that hangs, but the cause of the problem was really earlier. It was a stupid bug and really my fault, but it would help if Box2D could detect that problem before hanging.

Thanks for your help on this, I can now sleep properly

Top

 Post subject: Re: Box2D Freeze / HangPosted: Tue Mar 09, 2010 4:55 pm

Joined: Mon Jan 07, 2008 10:51 am
Posts: 1911
It's not my policy to put in a bajillion asserts. A NaN pretty much anywhere in the system is a problem, and naturally people need the earliest warning, or else it's about as useless as the error you actually got. Given the choice between checking everything, and nothing, I'll go with nothing.

I do have vague intentions of throwing in some cases where Box2D C++ silently ignores, at least.

Top

 Post subject: Re: Box2D Freeze / HangPosted: Thu Mar 18, 2010 11:04 am

Joined: Thu Mar 18, 2010 10:37 am
Posts: 3
Hi,

Is there a definitive fix for this? I've got a basic game engine running (Bike game :-) and when travelling at speed a collision causes box2d to hang and it times out...

From some debugging it appears to be the same problem occuring within b2TimeOfImpact

Thanks,

Mal

Top

 Post subject: Re: Box2D Freeze / HangPosted: Thu Mar 18, 2010 11:09 am

Joined: Wed Sep 09, 2009 6:29 pm
Posts: 18
I would check if you have any value (position, velocity or anything else) in your objects that are set to NaN. That was my problem, and it is unfortunately hard to find where you might be doing this. Box2D doesn't assert to make sure the values we feed it are valid.

Top

 Post subject: Re: Box2D Freeze / HangPosted: Tue Mar 23, 2010 4:51 am

Joined: Thu Mar 18, 2010 10:37 am
Posts: 3
Thanks for the info, but after a mammoth effort to test everything it didn't seem to be a NaN issue.

It turns out I was passing in too low a figure for "positionIterations" into world.Step(...)

A figure around 10 was fine for normal collisions, but upping this to 50 as velocity increases handles fast collisions much better.

Thanks again

Top

 Post subject: Re: Box2D Freeze / HangPosted: Tue Mar 23, 2010 2:59 pm

Joined: Mon Jan 07, 2008 10:51 am
Posts: 1911
50 is a ridiculously high quantity. Something is wrong if that is necessary.

Top

 Post subject: Re: Box2D Freeze / HangPosted: Tue Mar 23, 2010 3:06 pm

Joined: Thu Mar 18, 2010 10:37 am
Posts: 3
To be fair I haven't tried much lower figures yet, and the impact was happening at great velocity.

I'll try lower numbers >10 and post again when I've done that...

Cheers

Top

 Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending
 Page 2 of 3 [ 22 posts ] Go to page Previous  1, 2, 3  Next

 All times are UTC - 8 hours [ DST ]

Who is online

Users browsing this forum: Bing [Bot] and 4 guests

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

 Search for: