Weird physics behavior with Chrome
deybacsi

Hello guys,

I have noticed an interesting thing.

Yesterday I created a small project, it worked very well. Today when I loaded & tried it, it was always paused by the debugger. I was not able to figure out the main reason, why it's happening. Then I've found, I have a physics object with gravityScale set to a negative number. When I set it to a positive number, all things goes as expected.

Finally I restarted Chrome, and everything went well, without any modification. o_O (With negative gravityScale)

It's not so easy to reproduce the issue, because it happens so randomly. About a week ago, when I noticed first time this weird thing was, when I just played around with wade, and the gui without any code, just 1 or 2 objects with default values and physics behavior.

I don't know what causes the problem, maybe Chrome or box2d has some bugs, or anything else, but the Chrome restart solves it. (Of course I didn't saved, where was the dubugger stopped, to take an inner look to what causes the problem ;)) sry )
All of the cases Chrome was opened a long time ago.

It's just an info to others, who will face this issue in the future.

Freshly installed Windows 7 64 bit / Latest Chrome version - 56.0.2924.87 (64-bit) / Wade online editor

All 6 Comments
Gio

Hi

I'd like to reproduce this problem to see if there's anything I can do to fix it. So what should I do...

1. Set up a scene with a couple of PhysicsObjects

2. Set a negative gravityScale on one of them

3. Leave it running for a long time

4. See if anything gets caught by the debugger

Does that sound about right? Do I need to leave it running on a background tab? How long do you think?

Thanks

deybacsi

Hm, not exactly, but I think I didn't wrote it clearly.

I have created a project, what clones a physics object from template. This had a gravityScale=-1.

Everything was well, I saved the project, and went to sleep.

Yesterday I browsed the net for a few hours, then I opened a tab, opened wade, and tried to launch my previously saved project. (What was untouched)

And then come this weird debug stop. Exactly when the clone project was created with wade.addsceneobject.

If I modified the gravityScale to any positive, then it worked.

Then I thought to restart the browser, and it worked again, like before.

So Wade wasn't running for a long time nor the project. It dropped the debug stop right after the first launch.

But Chrome was opened for a few hours, with lots of tabs, this is why I think its not a Wade issue.

I try to reproduce it again. Can you tell me what type of informations should help you? Because those debugger things didn't tell me so much :D

deybacsi

Good news everyone! :D

It's simplier to reproduce it, than I expected. I created a new project with one object, and gravityScale=-1. All other things are the defaults.

When the "Developer tools" (Ctrl-Shift-I) is open in Chrome, it always pauses the code, when a physics object is added to scene with negative gravityScale property.

When I close the window, and start again, everthing works. I've tried it with all docking modes (right, bottom, separate window) several times.

This was exactly the same, when this happened with my previous code. All the time, when I added a new object to the scene with negative gravityScale, it was paused. Of course, because I left open the DevTools window. LOL.

I don't know what is the root cause of the problem, so I made a small video for you, and a screenshot where the debugger stops. (Sorry, the end of the video was cutted, free Fraps allows max 30 seconds long videos :D )

Hope this helps. ;)

And thanks for the great support. This Wade thingy is a good toy to play with :D Is there any possibility to donate a few bucks somehow, or to buy a license?

 

Video: https://youtu.be/aIj6ivqOwQI

Code: https://drive.google.com/open?id=0B07u6-NwblGHWUlYbnRyWjNTT0U

Screenshot from the debug window: https://drive.google.com/open?id=0B07u6-NwblGHYThxbHpWaEZvNUE

Gio

Thanks for that, it's definitely helped me track down the problem.

It appears that there is this line in box2d:

box2d.b2Assert(box2d.b2IsValid(a.gravityScale) && 0 <= a.gravityScale);

So basically box2d checks that gravityScale is positive, and warns you when it is negative. To be honest, I am not sure why it does that. Normally you would do this if a negative gravity scale did NOT work, to warn the user before something bad happens.

However a negative gravity scale does seem to work. On top of that, the box2d documentation does not state anything about gravity scale having to be a positive number. So I have no idea why they are doing that.

It seems to be perfectly safe to ignore. I would say you have 3 options here:

1. Be cautious and even if we don't know why the warning is there, set gravityScale to 0 and apply an upward force to your object.

2. Be the opposite of cautios, and somewhere when your scene is initialized, disable box2d asserts by setting box2d.ENABLE_ASSERTS = false

3. Just ignore it :)

Of course if you wanted to do this for all objects and not just one, there is a wade.physics.setGravity() functions that could be used.

Regarding your other question:

> Is there any possibility to donate a few bucks somehow, or to buy a license?

Really appreciated, but there is no such option at the moment. If you like Wade, please just spread the word and tell others about it :)

deybacsi

Wow, It was fast :D Thanks for the infos.

If I set the gravity to zero and apply a force to the object, it will go with linear speed, isn't it? I would like to create some nice flying objects what are going upwards and accelerating, like balloons. This is why I thought this negative gravity could be cool, and simple :)

I'll try to set the box2d.ENABLE_ASSERTS to false before object creation, then back to true, when it's done. Maybe it should work. Or not. I don't know. :D

Haha, ok, I will spread the word, and the greatness of Wade ;)

Gio

Well, that depends on how you apply the force.

PhysicsObject.applyForce(...) will only apply the force for one simulation step. If you did this for several simulation steps, it would behave like gravity, so non-linear movement. You could do

myObject.onUpdate = function()
{
    this.getBehavior('PhysicsObject').applyForce({x: 0, y: -1});
};
myObject.listenFor('onUpdate');

 

Post a reply
Add Attachment
Submit Reply
Login to Reply