棱柱关节导致崩溃-Box2D(cocos2d)

时间:2014-03-11 18:41:28

标签: iphone cocos2d-iphone box2d-iphone

我尝试设置一个棱柱形关节,但是我在运行时遇到了这个错误: 断言失败:(IsLocked()== false),函数CreateBody,文件/Users/Aether/Developer/JFRecode/JFRecode/libs/Box2D/Dynamics/b2World.cpp,第109行。

以下是屏幕边界的代码,因为我将它用作bodyB。

CGSize s = [CCDirector sharedDirector].winSize;


    //define screen boundaries
     // Create edges around the entire screen
     b2BodyDef groundBodyDef;
     groundBodyDef.position.Set(0,0);
     _groundBody = _world->CreateBody(&groundBodyDef);

     b2EdgeShape groundBox;
     b2FixtureDef groundBoxDef;
     groundBoxDef.shape = &groundBox;

     groundBox.Set(b2Vec2(0,0), b2Vec2(s.width/PTM_RATIO, 0));
     _bottomFixture = _groundBody->CreateFixture(&groundBoxDef);

     groundBox.Set(b2Vec2(0,0), b2Vec2(0, s.height/PTM_RATIO));
     _groundBody->CreateFixture(&groundBoxDef);

     groundBox.Set(b2Vec2(0, s.height/PTM_RATIO), b2Vec2(s.width/PTM_RATIO,
     s.height/PTM_RATIO));
     _groundBody->CreateFixture(&groundBoxDef);

     groundBox.Set(b2Vec2(s.width/PTM_RATIO, s.height/PTM_RATIO),
     b2Vec2(s.width/PTM_RATIO, 0));
     _groundBody->CreateFixture(&groundBoxDef);

以下是棱柱关节本身的代码

    b2PrismaticJointDef jointDef;
    b2Vec2 worldAxis(1.0f,0.0f);
    jointDef.collideConnected = true;
    jointDef.Initialize(_shipBody,_groundBody, 
                        _shipBody->GetWorldCenter(), worldAxis);
    _world->CreateJoint(&jointDef);

1 个答案:

答案 0 :(得分:0)

isLocked表示物理世界正在更新。这意味着您在世界步骤方法期间运行此代码,可能是在联系回调方法中或由于联系回调方法。延迟执行此代码直到世界步骤之后。