我在box2d中创建了物理体,如下所示,这是我的代码
b2BodyDef carBodyDef;
carBodyDef.position.Set(x/PTM_RATIO,y/PTM_RATIO);
carBodyDef.type=b2_dynamicBody; b2Body* carBody=physicsWorld->CreateBody(&carBodyDef);
b2CircleShape carShape;
carShape.m_radius=rad/40.0f;
b2FixtureDef carFixture;
carFixture.shape=&carShape;
carFixture.density = 1.0f;
carFixture.friction = 0.0f;
carBody->CreateFixture(&carFixture);
return carBody ;
当我运行应用程序时,它会崩溃, 与下面的错误 *断言失败:(IsLocked()== false),函数CreateBody, * in box2d
答案 0 :(得分:2)
那是因为你在执行Step()
b2World
函数时正在创建你的身体。执行此功能时无法创建新实体