0
\$\begingroup\$

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);
\$\endgroup\$
  • \$\begingroup\$ Read this and you'll be able to answer your own question. -1 for lack of research and no debugging effort. \$\endgroup\$ – MichaelHouse Mar 11 '14 at 20:54
  • 1
    \$\begingroup\$ 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. \$\endgroup\$ – user3084800 Mar 11 '14 at 20:59
  • \$\begingroup\$ 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). \$\endgroup\$ – MichaelHouse Mar 11 '14 at 21:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.