Skip to content

Physics do not spawn unless I create extra unused b2Vec2 #79

Description

@scott-cornwell

I noticed this completely by accident, but I fear this library is not stable enough to use because of this. I ended up with an extra b2Vec2 that I wasn't using, so I deleted it, but it caused my physics spawn to stop working. Made some other changes and now I had to add two unused b2Vec2 instances to get it to work. Makes absolutely no sense. All I can think is it's some kind of odd race condition?

// this "zero" vec2 does nothing and is not referenced anywhere but if I comment it out nothing spawns
const zero = new b2Vec2(0, 0) 
const pos = new b2Vec2(options.x, options.y)
let shape

const fixture = new b2FixtureDef()
fixture.density = 1.0
fixture.friction = 0.3
shape = new b2CircleShape()
shape.m_radius = options.radius

const bodyDef = new b2BodyDef()
bodyDef.set_type(b2_dynamicBody)

bodyDef.set_position(pos)

const body = this.world.CreateBody(bodyDef)
body.CreateFixture(fixture)
body.SetTransform(pos, 0)
body.SetAwake(true)
body.SetEnabled(true)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions