Question

This question is regarding Box2D v2.2.1 in JavaScript (compiled via Emscripten).

Some structs like b2Vec2 and b2BodyDef work perfectly fine.

I can create instances of both, like so:

new Box2D.b2Vec2(0,0); // returns b2Vec {..} 
new Box2D.b2BodyDef(); // returns b2BodyDef {..}

However, other structs such as b2MassData and b2Manifold do not, observe:

new Box2D.b2MassData(); // Error: "TypeError: undefined is not a function"
new Box2D.b2Manifold(); // Error: "TypeError: undefined is not a function"

This leads to strange behavior when dealing with classes which use these structs:

// Setup
gravity = new Box2D.b2Vec2( 0, 10 );  // returns b2Vec {..} 
world = new Box2D.b2World( gravity ); // returns b2World {..} 

// Problem 1
bodyDef = new Box2D.b2BodyDef();   // returns b2BodyDef {..} 
body = world.CreateBody(bodyDef);  // returns b2Body {..} 
massData = body.GetMassData();     // "TypeError: Cannot read property 'ptr' 
                                   // of undefined."

// Problem 2
contact = world.GetContactList();    // returns b2Contact {..}
manifold = contact.GetManifold();    // returns Object {..} NOT b2Manifold {..}
normal = manifold.get_localNormal(); // "TypeError: Object #<Object> has 
                                     // no method 'get_localNormal'."

How can I repair the use of these structures, and others like them?

Was it helpful?

Solution

This is most likely because those classes do not have a public constructor (or even any constructor at all). You'll need to add the constructors in the Box2D code.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top