Box2D Forums

It is currently Fri Apr 18, 2014 6:43 am

All times are UTC - 8 hours [ DST ]




Post new topic Reply to topic  [ 22 posts ]  Go to page 1, 2, 3  Next
Author Message
 Post subject: Box2D Freeze / Hang
PostPosted: Thu Mar 04, 2010 2:09 pm 
Offline

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

BorisTheBrave rightfully suggested we created new threads for issues, so here's a thread for the bug Don Pipo and I have been hitting.

From the main thread:
Quote:
Using trace debugs I've narrowed the problem to be around the b2World:SolveTOI() function. The for(;;) loop (// Find TOI events and solve them.) never ends, and the next for loop right after it (for (c = m_contactList; c; c = c.m_next)) loops 4-5 times, about 1 second per cycle.

I just tried the TestBed, and if you play the "Breakable" demo a few times, by throwing the attached blocks in the walls, you'll end up with a hang. I'm not quite sure if it's the same hang, but I thought I would add it anyways. If I find a better repro I'll post it here, for now that's all I've got.

Here's the error message I get when the testbed hangs
Quote:
Error: Error #1502: A script has executed for longer than the default timeout period of 15 seconds.
at Box2D.Dynamics.Contacts::b2Contact/IsSensor()
at Box2D.Dynamics::b2World/http://www.box2d.org/ns/b2internal::Solve()[C:\Users\Swah\flash\Box2dTest\box2dflash\Source\Box2D\Dynamics\b2World.as:1031]
at Box2D.Dynamics::b2World/Step()[C:\Users\Swah\flash\Box2dTest\box2dflash\Source\Box2D\Dynamics\b2World.as:602]
at TestBed::Test/Update()[C:\Users\Swah\flash\Box2dTest\box2dflash\Examples\TestBed\Test.as:104]
at TestBed::TestBreakable/Update()[C:\Users\Swah\flash\Box2dTest\box2dflash\Examples\TestBed\TestBreakable.as:78]
at Main/update()[C:\Users\Swah\flash\Box2dTest\box2dflash\Examples\Main.as:129]

Thanks for your help!


Top
 Profile  
 
 Post subject: Re: Box2D Freeze / Hang
PostPosted: Thu Mar 04, 2010 2:56 pm 
Offline

Joined: Mon Jan 07, 2008 10:51 am
Posts: 1911
I think I've seen this ONCE. It's rare. I'm looking into your other issue now. Perhaps you could take the time to find a deterministically reproducible circumstance? Try randomly generated them from seeds, until you hit lucky, and save that seed.


Top
 Profile  
 
 Post subject: Re: Box2D Freeze / Hang
PostPosted: Thu Mar 04, 2010 3:38 pm 
Offline

Joined: Tue Dec 01, 2009 2:19 pm
Posts: 34
Hi Swah!

Sorry, that you have this bug, too. But I'm happy that I'm not the only one with this problem^^ You wrote in the "Box2DFlash 2.1a Release"-Thread that the bug could have something to do with the b2World:SolveTOI() function. Tomorrow I will look if that confirms with my project.

Just a question: Do you use a raycast anywhere in your programm? Does the freeze-bug allways appear (with the same likelihood)?
The thing which confuses me most is that it seems to me that the chance of freezing can be increased by functions which have nothing to do with Box2D. :?:


Top
 Profile  
 
 Post subject: Re: Box2D Freeze / Hang
PostPosted: Thu Mar 04, 2010 3:53 pm 
Offline

Joined: Mon Jan 07, 2008 10:51 am
Posts: 1911
Actually, I'm thinking that is bug is to do with the .Split() method, which attempts to be smarter than it needs to be. I'll rewrite it soon. Don't get me wrong though, I'd love to find a bug in the SolveTOI stuff, I'm pretty sure one is lurking there.


Top
 Profile  
 
 Post subject: Re: Box2D Freeze / Hang
PostPosted: Thu Mar 04, 2010 4:27 pm 
Offline

Joined: Wed Sep 09, 2009 6:29 pm
Posts: 18
Thanks for the help guys - I will definitively try the seed idea, sounds like a smart thing to do.

I've got a good repro in my game, which triggers the hang fairly regularly, so I'll investigate from there for a little while. I never dove into the Box2D internal code, so this might take me a while :?

Re: Don Pipo - I've got raycasts, but the bug still happens if I take them out.


Top
 Profile  
 
 Post subject: Re: Box2D Freeze / Hang
PostPosted: Thu Mar 04, 2010 4:42 pm 
Offline

Joined: Wed Sep 09, 2009 6:29 pm
Posts: 18
Alright I just found that line 1238 of b2World.as -
Code:
toi = c.ComputeTOI(bA.m_sweep, bB.m_sweep);

is what takes a _lot_ of time to compute (+- 1 second per call)

I'll keep investigating...

On the Split() - yeah I'm not using that specific feature, so there could be two bugs here.


Top
 Profile  
 
 Post subject: Re: Box2D Freeze / Hang
PostPosted: Thu Mar 04, 2010 4:50 pm 
Offline

Joined: Wed Sep 09, 2009 6:29 pm
Posts: 18
If I set
Code:
const k_maxIterations:int = 1000;
to 10, in b2TimeOfImpact:TimeOfImpact, the hang is definitively lower. I'm not even sure why we compute TimeOfImpact, but I'm slowly narrowing where the problem is.


Top
 Profile  
 
 Post subject: Re: Box2D Freeze / Hang
PostPosted: Thu Mar 04, 2010 5:20 pm 
Offline

Joined: Wed Sep 09, 2009 6:29 pm
Posts: 18
Alright - the problem is that when the hang occurs, a for loop is trying to compute something and it never converges. I've got no idea what that loop is for, and a quick explanation could help me finding out what I'm doing that is either wrong or unusual. I'm not really sure how I can investigate further, unless you want me to report on some variables. So I guess I should be giving you a proper testbed, but I'm not sure I'll be able to create one that does the same hang.

The loops is at b2TimeOfImpact.as:line 173, and it always reaches rootIterCount = 50
Code:
// Determine when intervals intersect
var rootIterCount:int = 0;

for (;; )
{
   // Use a mis of the secand rule and bisection
   var x:Number;
   if (rootIterCount & 1)
   {
      // Secant rule to improve convergence
      x = x1 + (target - f1) * (x2 - x1) / (f2 - f1);
   }
   else
   {
      // Bisection to guarantee progress
      x = 0.5 * (x1 + x2);
   }
   
   sweepA.GetTransform(s_xfA, x);
   sweepB.GetTransform(s_xfB, x);
   
   var f:Number = s_fcn.Evaluate(s_xfA, s_xfB);
   
   if (b2Math.Abs(f - target) < 0.025 * tolerance)
   {
      newAlpha = x;
      break;
   }
   
   // Ensure we continue to bracket the root
   if (f > target)
   {
      x1 = x;
      f1 = f;
   }
   else
   {
      x2 = x;
      f2 = f;
   }
   
   ++rootIterCount;
   ++b2_toiRootIters;
   if (rootIterCount == 50)
   {
      break;
   }
}

b2_toiMaxRootIters = b2Math.Max(b2_toiMaxRootIters, rootIterCount);
}


As always, thanks for your help. I'm sure glad there's reliable support!


Top
 Profile  
 
 Post subject: Re: Box2D Freeze / Hang
PostPosted: Thu Mar 04, 2010 6:54 pm 
Offline

Joined: Wed Sep 09, 2009 6:29 pm
Posts: 18
I should add that after the hang is finished, both bodies that were in contact seem to disappear. The bodies still exist, but GetPosition() returns null and the shapes don't display in debug view.


Top
 Profile  
 
 Post subject: Re: Box2D Freeze / Hang
PostPosted: Sun Mar 07, 2010 1:01 pm 
Offline

Joined: Tue Dec 01, 2009 2:19 pm
Posts: 34
Well, I just figured out that my function with world.Step() isn't the only function that stops executing randomly. I found at least one other class with an "onEnterFrame"-function which stops receiving ENTER_FRAME events and both functions stop at the same time. Probably my freeze-bug isn't caused by Box2D itself, like I thought. I just have the problem that world.Step() isn't called anymore, because my EventListener doesn't get ENTER_FRAME events anymore and I don't know why.
Maybe I found help in a general flash forum.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 22 posts ]  Go to page 1, 2, 3  Next

All times are UTC - 8 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 2 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