# Prismatic Joint causes a crash-Box2D(cocos2d)

tried to set up a prismatic joint, but I get this error upon run time: Assertion failed: (IsLocked() == false), function CreateBody, file /Users/Aether/Developer/JFRecode/JFRecode/libs/Box2D/Dynamics/b2World.cpp, line 109.

Here is the code for the screen boundaries since I am using it as 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);


Here is the code for the prismatic joint itself

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

• Read this and you'll be able to answer your own question. -1 for lack of research and no debugging effort. – MichaelHouse Mar 11 '14 at 20:54
• I dont believe the down vote is deserved since 1.) Im using C++, 2.) this has nothing to do with removing objects. 3.) The solution was to actually move the boundary method after the world was created since it was crashing on the _world->createFixture method since the world hadn't been created at that point. – user3084800 Mar 11 '14 at 20:59
• I didn't say the questions were the same, however the underlying problems are very similar. Both could easily be solved by reading the error message, and debugging. Further, searching for "Assertion failed: (IsLocked() == false), function CreateBody" returns a number of results for how to solve the problem (thus lack of research). – MichaelHouse Mar 11 '14 at 21:04