Box2d SetAngle Problem

BlitzMax Forums/Brucey's Modules/Box2d SetAngle Problem

Armitage 1982(Posted 2009) [#1]
Hi Brucey

First I ask into the box2d forum because I think it was very related to the engine.
Then I discovered that the b2BodyDef::setAngle() is not present in the official API of Box2d.

My problem only happen with dynamic polygons object (created with b2PolygonDef).
Static or b2CircleDef give no freezing problem !

So, in my level editor when I modify any dynamic cube (for example) to change is b2BodyDef angle via setAngle(degrees:float) in order to re-create it after this new definition setting, my game freeze...

I look into the glue.cpp quickly and find this setter :

void bmx_b2bodydef_setangle(b2BodyDef * def, float32 angle) {
	def->angle = angle * 0.0174533f;
}


Maybe there is a problem somewhere with this degrees=>radians shortcut ?
I don't know, this is very strange since it works fine in any other situation.
And my code is using the exact same re-creation code for any definition.

Is this a bug ??


Brucey(Posted 2009) [#2]
Is this a bug ??

Possibly.

I can instead create def specific functions rather than the shared one they are all using. It might fix it.


Armitage 1982(Posted 2009) [#3]
Maybe...
I was thinking of this too.
I'll wait some answers at the box2d forum (http://www.box2d.org/forum/viewtopic.php?f=3&t=2077) and double check my code until then.

Thanks


Brucey(Posted 2009) [#4]
I had a closer look at bodydef, and it seems to be okay.
Are you sure your instance of the def object is still valid when you try to use it?

Or perhaps it is the polygondef which is causing problems?


Armitage 1982(Posted 2009) [#5]
The def object is still valid when used since it's part of a super-type.
It's probably coming from my code since I can't reproduce this bug :(

Maybe I have to forget the idea of rotating bodyDef in the level editor for a while and just go on.


Brucey(Posted 2009) [#6]
As long as the body def pointer is valid you should, presumably, be able to call any of the methods as often as you like - without issue.
And the only way that the pointer will be freed is when the BlitzMax object is GC'd.

At least, that's what should be happening :-)


Armitage 1982(Posted 2009) [#7]
Since it's pretty hard to track internal box2d objects and since I'm only using the bodyDef as a values container I try to get rid of that problem by adding one more Field to my object called angle.

Instead of using bodyDef::setAngle() to save my angle before any object re-setuping I only set this new Field.

But the freeze problem is still there so there is probably something weird in my polygonDef finalization.


Armitage 1982(Posted 2009) [#8]
I think I find the problem :D

In fact I'm using a super-type b2ShapeDef.
This type is passed by reference in my set Object Definition function.

The problem reside in one of these initialisation (maybe all)
shapeDef.SetDensity(vDensity)
shapeDef.SetFriction(vFriction)
shapeDef.SetRestitution(vRestitution)
shapeDef.GetFilter().SetCategoryBits(vFilterCategoryBits)
shapeDef.GetFilter().SetGroupIndex(vFilterGroupIndex)
shapeDef.GetFilter().SetMaskBits(vFilterMaskBits)


I suppose since there is new b2shapeDef (for circle, poly, etc.) that box2d setup those in a completely different way based on the type.
And since I'm not directly using b2PolygonDef or b2CircleDef, the default method present in b2ShapeDef just don't work correctly.

That was a difficult one ^^

But then ?
Does that mean that b2ShapeDef method are broken somewhere ?