box2d icon indicating copy to clipboard operation
box2d copied to clipboard

Step() function get stuck

Open xiajiaonly opened this issue 5 years ago • 17 comments

image

when a dynamic body is covered by many static bodies. for example: use mouse to draw many lines,a line is a static body. then the dynamic body will be blocked by the lines. when the lines cover the dynamic body,the Step() will get stuck. maybe 10 lines or more or less.

How to solve this problem? image

The FPS is very very low.

xiajiaonly avatar Feb 10 '19 06:02 xiajiaonly

What behaviour do you want in this scenario?

On Sun, 10 Feb 2019, 06:02 xiajiaonly <[email protected] wrote:

[image: image] https://user-images.githubusercontent.com/4102643/52530133-83426e00-2d3b-11e9-8e7d-a972e8ec09da.png

when a dynamic body is covered by many static bodies. use mouse to draw many lines,a line is a static body. then the dynamic body will be blocked by the lines. when the lines cover the dynamic body,it will get stock.

How to solve this problem?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/erincatto/Box2D/issues/532, or mute the thread https://github.com/notifications/unsubscribe-auth/AZZvlwbaTzsH3QwKbCJi_MaPrJNSrPpeks5vL7XbgaJpZM4ay6EG .

HughPH avatar Feb 10 '19 08:02 HughPH

I think the dynamic body should be stuck and in a static state. The "stuck" in the topic title mean the game stuck,not the object stuck.

xiajiaonly avatar Feb 10 '19 08:02 xiajiaonly

I'm not sure I understand. If it's static, it won't move. If it's blocked, it won't move.

On Sun, 10 Feb 2019, 08:26 xiajiaonly <[email protected] wrote:

I think the dynamic body should be stuck and in a static state.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/erincatto/Box2D/issues/532#issuecomment-462113465, or mute the thread https://github.com/notifications/unsubscribe-auth/AZZvl4p0E7iC_JBysMPTcrDD74MGc4NEks5vL9fKgaJpZM4ay6EG .

HughPH avatar Feb 10 '19 10:02 HughPH

It will jump in box2D.the dynamic body will jump to a valid position. In reality, it should be an illegal state. Whatever the state it is, it should not increase the consumption of world's Step ().

xiajiaonly avatar Feb 10 '19 11:02 xiajiaonly

Ok, so it's not "stuck".

If a dynamic object is over another object, it will push away from the centre of the other object. Most physics engines will do the same. If you want your object to be static, make it static. Otherwise it will have dynamic behaviours. If you want to pretend the object is on another plane, so they shouldn't interact, you should use the category bits and mask bits.

There are great tutorials at www.iforce2d.net/b2dtut/

On Sun, 10 Feb 2019, 11:01 xiajiaonly <[email protected] wrote:

It jumps in box2D. In reality, it should be an illegal state. Whatever the state it is, it should not increase the consumption of world's Step ().

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/erincatto/Box2D/issues/532#issuecomment-462122684, or mute the thread https://github.com/notifications/unsubscribe-auth/AZZvlw_GHEudPJn6XLsPNNYF1bnmk0vkks5vL_v0gaJpZM4ay6EG .

HughPH avatar Feb 10 '19 12:02 HughPH

T.T,You misunderstood me.I don't care about the state of the object. What I care about is that the Step() function will be stuck.Maybe this needs a GIF to explain it more accurately.

xiajiaonly avatar Feb 10 '19 12:02 xiajiaonly

Ok, so you call Step and it locks up?

How many iterations are you asking it to perform?

On Sun, 10 Feb 2019, 12:56 xiajiaonly <[email protected] wrote:

T.T,You misunderstood me.I don't care about the state of the object. What I care about is that the Step() function will be stuck.Maybe this needs a GIF to explain it more accurately.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/erincatto/Box2D/issues/532#issuecomment-462130530, or mute the thread https://github.com/notifications/unsubscribe-auth/AZZvl5dZiWfR_vfiRLMmTBcUzC6xdzZbks5vMBcAgaJpZM4ay6EG .

HughPH avatar Feb 10 '19 13:02 HughPH

m_pWorld->Step(1.0f / 60.0f, 4, 2); not lock up,it's just slow. maybe need 2000ms。

xiajiaonly avatar Feb 10 '19 13:02 xiajiaonly

It would seem strange for this not to have been discovered before. You could use iforce2d's RUBE to model the same scene (export a breaking example or create the objects in RUBE, save it, and change the file in notepad to have the same object properties) and see if that suffers the same issue. If it does, you have something reproducible. Otherwise, it's likely something peculiar to your code.

 - Hugh

"Bureaucracy is the epoxy that greases the wheels of progress."

  • James H. Boren

On Sun, 10 Feb 2019 at 13:25, xiajiaonly [email protected] wrote:

m_pWorld->Step(1.0f / 60.0f, 4, 2);

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/erincatto/Box2D/issues/532#issuecomment-462132668, or mute the thread https://github.com/notifications/unsubscribe-auth/AZZvl9YPvqv7t5VHeKO3Wq4lw5CmEgE2ks5vMB3ZgaJpZM4ay6EG .

HughPH avatar Feb 10 '19 17:02 HughPH

the code modify from the testbed,is here:https://github.com/xiajiaonly/TestB2D image Because of the limited time, I haven't written a typical example. I will revise this example in the next step to make the problem more typical.

xiajiaonly avatar Feb 10 '19 22:02 xiajiaonly

I looks like the complexity of your static model is the problem. Simplify, then simplify again.

erincatto avatar Feb 10 '19 23:02 erincatto

Yeah, I was going to say that looks pretty crazy. How many objects do you have there?

On Sun, 10 Feb 2019, 23:28 Erin Catto <[email protected] wrote:

I looks like the complexity of your static model is the problem. Simplify, then simplify again.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/erincatto/Box2D/issues/532#issuecomment-462191727, or mute the thread https://github.com/notifications/unsubscribe-auth/AZZvl8kw78YEOHHKzFIP1a2pUnYLC2eRks5vMKslgaJpZM4ay6EG .

HughPH avatar Feb 10 '19 23:02 HughPH

It doesn't need a lot. In some cases, just a few. In the above examples, some are unnecessary, just to illustrate the problem. I will revise the above example to make the problem more prominent. I just got up. Wait a minute.

xiajiaonly avatar Feb 11 '19 02:02 xiajiaonly

I have updated the code. image “body sum” just the lines sum,in up pic. image “body sum” include lines sum and balls sum,in up pic.

xiajiaonly avatar Feb 11 '19 03:02 xiajiaonly

Are you trying to make a solid body? You should use Polygons, not Lines...

On Mon, 11 Feb 2019, 03:48 xiajiaonly <[email protected] wrote:

I have updated the code. [image: image] https://user-images.githubusercontent.com/4102643/52545456-9ebc8000-2df2-11e9-8ae5-0ea7db23cdf8.png “body sum” just the lines sum,in up pic. [image: image] https://user-images.githubusercontent.com/4102643/52545478-ce6b8800-2df2-11e9-8380-00f06dc932b3.png “body sum” include lines sum and balls sum,in up pic.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/erincatto/Box2D/issues/532#issuecomment-462213098, or mute the thread https://github.com/notifications/unsubscribe-auth/AZZvl6rDFGYw042chTECNZzVQnaoJdagks5vMOf6gaJpZM4ay6EG .

HughPH avatar Feb 11 '19 11:02 HughPH

Yes, it's the same.

In some cases, the efficiency of b2World::SolveTOI() is very low.

xiajiaonly avatar Feb 11 '19 13:02 xiajiaonly

I experimented with this test case. The performance problem is definitely SolveTOI. The over-constrained bodies are trying to prevent tunneling. The solver fights harder for circles than polygons.

erincatto avatar Apr 06 '20 03:04 erincatto