问题
I am creating the physical body in box2d as below , this si my code
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 ;
When am running the app, its getting crash , with the below erro *Assertion failed: (IsLocked() == false), function CreateBody,*in box2d
回答1:
That's because you are creating your body during execution of Step()
function of b2World
. You can't create new bodies while this function is executing
来源:https://stackoverflow.com/questions/9428367/creating-physic-body-in-cocos2d