Page 1 of 1

Stuck at world.step

Posted: Mon Dec 25, 2017 7:29 pm
by soylomass
Hi again.

One year ago I made a post (viewtopic.php?f=3&t=312) about the engine getting randomly stuck at world.step, because of that problem I had to switch to libgdx-box2d.

Now, I'm making a new game, and I decided to use dyn4j because I really like it, among other advantages, but the problem happened again.

This new game was made from scratch. This time I've decided to find a solution as I don't want to switch engines.

In the old post, I found out that the engine was getting stuck at:


// after all has been updated find new contacts
// this is done so that the user has the latest contacts
// and the broadphase has the latest AABBs, etc.
this.detect();


This time it gets stuck at the same method, so I added prints inside it to see where exactly it happens, and when it finally crashed again, this was the result (got stuck on the red line):

// get their transforms
Transform transform1 = body1.getTransform();
Transform transform2 = body2.getTransform();

Convex convex2 = fixture2.getShape();
Convex convex1 = fixture1.getShape();

Penetration penetration = new Penetration();
// test the two convex shapes
System.out.print("a");
if (this.narrowphaseDetector.detect(convex1, transform1, convex2, transform2, penetration)) {
// check for zero penetration
System.out.print("b");




I'll continue trying to find the cause. Meanwhile, if anyone can help me, I'd be greatly pleased.

Thanks in advance.

PS: All the code is on World.java (org.dyn4j.dynamics.World)

PS2: I'm using all the default world settings except for gravity. Maybe I should try using another implementation of Narrowphase, given that it gets stuck at narrowphase.detect

UPDATE: I'll try using SAT instead of the default GJK, and if the problem happens again, I'll start checking where on narrowphase.detect it gets stuck.

Re: Stuck at world.step

Posted: Tue Dec 26, 2017 5:17 am
by zoom
If I recall correctly no one managed to replicate your results? I think this indicates something in your setup, either some world settings, which isn't likely, or more likely you have some fixture/convex that is special somehow. Just tossing ideas here but maybe some degenerate convex, like 0 area or some floating point value that is NaN.
Is there some test case you could share or sample code that shows the problem? The best way to get this fixed is to make it so others can replicate the problem. My humble suggestion is that you focus your effort into making a test case rather than debugging on your own.

Re: Stuck at world.step

Posted: Tue Dec 26, 2017 10:30 am
by soylomass
zoom wrote:If I recall correctly no one managed to replicate your results? I think this indicates something in your setup, either some world settings, which isn't likely, or more likely you have some fixture/convex that is special somehow. Just tossing ideas here but maybe some degenerate convex, like 0 area or some floating point value that is NaN.
Is there some test case you could share or sample code that shows the problem? The best way to get this fixed is to make it so others can replicate the problem. My humble suggestion is that you focus your effort into making a test case rather than debugging on your own.


This time the bodies are all boxes and circles, and some of the boxes (platforms) are weldjointed one at the side of the other, forming a bigger platform (1x2, 2x2, etc). The only thing that might not be right is that the welded platforms are not overlapping, and the weld point is only on one of the boxes, but I don't think that could be the problem, right?

I'd like to make a test case, but even if I did it, the problem doesn't happen always, and actually it happens while no bodies or joints are being created, only maybe forces being applied.

The other time I decided to switch to box2d because the problem happened only when people were playing it, and I couldn't make it happen when hosting the server on my PC. This time it happens on my PC so I can try to find the cause without disturbing players.

Re: Stuck at world.step

Posted: Tue Dec 26, 2017 10:57 am
by William
soylomass wrote:This time the bodies are all boxes and circles, and some of the boxes (platforms) are weldjointed one at the side of the other, forming a bigger platform (1x2, 2x2, etc). The only thing that might not be right is that the welded platforms are not overlapping, and the weld point is only on one of the boxes, but I don't think that could be the problem, right?

I wouldn't expect that to be an issue.

soylomass wrote:I'd like to make a test case, but even if I did it, the problem doesn't happen always, and actually it happens while no bodies or joints are being created, only maybe forces being applied.

But there are still bodies in the world right? The detect method does nothing with forces, it only checks for collisions between two shapes, so for it to halt there, there must be some shapes in the world.

What would be useful is if you could print out the convex shapes and their transforms at the time the application hangs (toString should give sufficient information). This could allow us to produce a minimal test case. Some other questions:

  1. Does it always hang at that line (the line after you print "a")?
  2. When you used Sat as the narrowphase collision detector, did that prevent the hanging?
  3. Can you turn off Continuous Detection and test again (Settings.setContinuousDetectionMode(ContinuousDetectionMode.NONE));

Thanks,
William

Re: Stuck at world.step

Posted: Tue Dec 26, 2017 12:15 pm
by soylomass
Will try to do what you asked and answer your questions as soon as it gets stuck again (if it does, because I changed to SAT, and even if it does it may take a time, as it's totally random).

By the way, is there a performance lose by using SAT instead of GJK?

About the first question, last time was the firs time I debugged inside this.detect();

But I can affirm that every time it gets stuck at this.detect();

Re: Stuck at world.step

Posted: Tue Dec 26, 2017 8:55 pm
by William
soylomass wrote:Will try to do what you asked and answer your questions as soon as it gets stuck again (if it does, because I changed to SAT, and even if it does it may take a time, as it's totally random).

soylomass wrote:About the first question, last time was the firs time I debugged inside this.detect();

But I can affirm that every time it gets stuck at this.detect();

Thanks, that will help us track down the problem.

soylomass wrote:By the way, is there a performance lose by using SAT instead of GJK?

SAT is probably faster, but it doesn't work with some shapes (Ellipse and HalfEllipse only work with GJK).

William

Re: Stuck at world.step

Posted: Tue Jan 02, 2018 9:50 pm
by soylomass
I want to report that until now it hasn't got stuck once while using SAT. Will keep testing given its randomness, but more time has passed than between previous stuck events.

Re: Stuck at world.step

Posted: Mon Jan 08, 2018 10:22 pm
by William
soylomass wrote:I want to report that until now it hasn't got stuck once while using SAT.

That is good news.

soylomass wrote:Will keep testing given its randomness,

Please do, I'm very interested in fixing this issue.

William