iphone - Prismatic Joint causes a crash-Box2D(cocos2d) -
i tried set prismatic joint, error upon run time: assertion failed: (islocked() == false), function createbody, file /users/aether/developer/jfrecode/jfrecode/libs/box2d/dynamics/b2world.cpp, line 109.
here code screen boundaries since using bodyb.
cgsize s = [ccdirector shareddirector].winsize; //define screen boundaries // create edges around 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 code prismatic joint itself
b2prismaticjointdef jointdef; b2vec2 worldaxis(1.0f,0.0f); jointdef.collideconnected = true; jointdef.initialize(_shipbody,_groundbody, _shipbody->getworldcenter(), worldaxis); _world->createjoint(&jointdef);
islocked indicates physics world being updated. means you're running code during world step method, in or result of contact callback method. delay executing code until after world step.
Comments
Post a Comment