kripken / box2d.js

Port of Box2D to JavaScript using Emscripten
1.33k stars 196 forks source link

"Assertion: 20" Error #24

Closed Joncom closed 11 years ago

Joncom commented 11 years ago

This code results in an Assertion: 20 error message. Not sure what I'm doing wrong, and the error message does not give much information.

var gravity = new Box2D.b2Vec2( 0, 0 );
var world = new Box2D.b2World( gravity );

var bodyDef = new Box2D.b2BodyDef();
bodyDef.type = Box2D.b2_staticBody;
bodyDef.position = new Box2D.b2Vec2(0,0);
var body = world.CreateBody( bodyDef );

var shape = new Box2D.b2PolygonShape();
shape.SetAsBox(1,1);

var fixture = new Box2D.b2FixtureDef();
fixture.shape = shape;

body.CreateFixture( fixture );
bunnyhero commented 11 years ago

So far I've seen Assertion:20 when trying to assign a property directly rather than using the corresponding set_xxx() method.

Try this (untested):

var gravity = new Box2D.b2Vec2( 0, 0 );
var world = new Box2D.b2World( gravity );

var bodyDef = new Box2D.b2BodyDef();
bodyDef.set_type( Box2D.b2_staticBody );
bodyDef.set_position(new Box2D.b2Vec2(0,0));
var body = world.CreateBody( bodyDef );

var shape = new Box2D.b2PolygonShape();
shape.SetAsBox(1,1);

var fixture = new Box2D.b2FixtureDef();
fixture.set_shape( shape );

body.CreateFixture( fixture );
Joncom commented 11 years ago

Changing fixture.shape = shape; to fixture.set_shape( shape ); fixed it. Thanks!