kripken/box2d.js — Issue #2: Fails to set mass and inertia when using b2FixtureDef
Author: eweitnauer
Created: 2012-03-05 17:21:48+00:00
State: open

There seems to be a problem when using b2FixtureDef to create a fixture. With the following code

```javascript
function createBody(x, y, rot, dynamic) {
var bodyDef = new Box2D.b2BodyDef();
bodyDef.set_position(new Box2D.b2Vec2(x, y));
bodyDef.set_angle(rot);
bodyDef.set_type(dynamic ? Box2D.b2_dynamicBody : Box2D.b2_staticBody);
var body = world.CreateBody(bodyDef);
var shape = new Box2D.b2PolygonShape();
shape.SetAsBox(1, 0.1);
var fixtureDef = new Box2D.b2FixtureDef();
fixtureDef.set_density(1);
fixtureDef.set_shape(shape);
body.CreateFixture(fixtureDef);
return body;
}
```
I get the error "Uncaught Assertion failed: m_I > 0.0f, at Box2D_v2.2.1/Box2D/Dynamics/b2Body.cpp, 319, void b2Body::ResetMassData()".
What I was also wondering about is why the b2MassData is not available as javascript class in the Box2D namespace.