Problem with Box2D with only rectangles in

I've just started a new CocosSharp project in 1.5 (windows) and I have a small scene with about 20 boxes, and when I call world.Step() in the Schedule, I get the following exception

An unhandled exception of type 'System.InvalidCastException' occurred in box2d.dll

Additional information: Unable to cast object of type 'Box2D.Collision.Shapes.b2EdgeShape' to type 'Box2D.Collision.Shapes.b2CircleShape'.

My rectangle creation is based on the latter part of the Gone Bananas example (but in F#)

let bodyDef = BodyDef()
    bodyDef.allowSleep <- true
    bodyDef.position <- b2Vec2
                            (float32 (convertPixelsToMeters x), 
                             float32 (convertPixelsToMeters y))

let shape = b2EdgeShape()
shape.Set(
    b2Vec2.Zero,
    b2Vec2(float32 (convertPixelsToMeters width)
                 float32 (convertPixelsToMeters height)))

let body = world.CreateBody(bodyDef)
body.BodyType <- if isDynamic then BodyType.b2_dynamicBody else BodyType.b2_staticBody

let fd = b2FixtureDef(shape = shape)
fd.density <- 1.0f

let fixture = body.CreateFixture(fd) 
body

The exception occurs whenever a dynamic body contacts a static body, but if I make the dynamic body a b2CircleShape then everything works. Anyone else had any issues with Box2D?

Sign In or Register to comment.