Body Teleported without reason? — Step issue

Hello everybody,
I am having troubles with Box2D.
I don't know why but at the first call, the Step() function teleports my hero (dynamic body) to the y position 0...
I checked all my code, and this is not because of any SetTransform, because I toggled all of it off.

I dumped the body and the log is exactly the same before and after the bugged step (except for the y pos).

Did anyone already had this issue?
Maybe it's a bug of the engine...

Thanks a lot 😉

PS : It appears with both 2.2.1 & 2.3? latest svn checkout
Where are you expecting it to go instead of 0,0 and how did you set it to go there?
Hey, thanks for your answer 😉

That's the issue, this body is not supposed to move. It is supposed to be at a its starting point (ex: b2Vec2(2,4)) but instead of that it is "teleported" after the first Step() call to y pos 0 (same ex: b2Vec2(2,0)).
This is happening on every levels of my game.

To be precise I never saw that issue on iOS, only on the Mac version of my game (related to CPU performance ?)...

It also happens with a non-time fixed call and with a semi-time fixed.

Thanks a lot.
Is it colliding with something, or is it connected to another body with a joint? How about if it is the only body in the world? I would guess it is being affected by an interaction with another body.
thanks for your advices !

Finally found what's the issue, but I haven't been able to fix it yet.
And yes, this seems to be a bug from the engine.

What I do at the first frame is to rebuild the body of my main character and especially setting manually a mass to it.
Then the SetMassData() function does its job, BUT at the end it moves the center of the mass. Here is the problem, if I comment those last lines, the body isn't teleported.
Are we talking about position or center of mass? You need to be more specific about what you are doing.
For example, if you did this:
Code:
body->SetTransform( b2Vec2(2, 4), 0 );
b2Vec2 pos = body->GetPosition();
... and then the value of pos was not (2,4) then it would be a bug. Or if you set the initial position of the body in the bodyDef and it was not (2,4) immediately after creation it would be a bug.
However, if you are running Step() then many other factors come into play.

One of the reasons for having the SetMassData() function is so that you can move the center of mass of a body so naturally, using it could very well change the position of the center of mass (GetWorldCenter), but it should not change the position of the body (GetPosition).
Thanks a lot for all your answers.
This seems to be now fixed with an "ugly fix". What I did is to position the object up just before SetMassData(), to cancel any unwanted collision.
I think that when I was changing the shape radius, it was then overlapping the ground. Then, calling SetMassData() made the "teleport" bug appear.

Thanks again 😉
I'm not quite sure what caused the bug, but I do have an insight for you. When Box2D processes time advancement of a body, it uses a b2Sweep. Velocity and position values are copied between that struct and a b2Body class. Somehow, an invalid older value from a b2Sweep was being copied into a b2Body. SetMassData and other similar b2Body calls force the body's transform to be synced up, which is why calling SetMassData at the end fixed things. I hope I was clear, I didn't actually dig into details for you, but I had dealt with similar issues myself in the past.
pTymN wrote:
I'm not quite sure what caused the bug, but I do have an insight for you. When Box2D processes time advancement of a body, it uses a b2Sweep. Velocity and position values are copied between that struct and a b2Body class. Somehow, an invalid older value from a b2Sweep was being copied into a b2Body. SetMassData and other similar b2Body calls force the body's transform to be synced up, which is why calling SetMassData at the end fixed things. I hope I was clear, I didn't actually dig into details for you, but I had dealt with similar issues myself in the past.


You were absolutely clear!
Thanks for those clarifications 😉

Original thread: https://box2d.org/forum/viewtopic.php?t=8972