Prismatic joint bug in C++ version since 2.1.2

Hello! I am writing an application using box2d physics & I found a prismatic joint bug (as i think):
Code:
    b2BodyDef bodyLadder1Def;
    bodyLadder1Def.type = b2_dynamicBody;
    bodyLadder1Def.position.Set(400 / PTM_RATIO, 400 / PTM_RATIO); // PTM_RATIO = 46
    bodyLadder1Def.angularDamping  = 0.5f;
    bodyLadder1Def.linearDamping   = 0.5f;

    b2Vec2 verticesLadder1[4];
    verticesLadder1[0].Set(0.0000f, 0.0000f);
    verticesLadder1[1].Set(2.6739f, 0.0000f);
    verticesLadder1[2].Set(2.6739f, 0.4130f);
    verticesLadder1[3].Set(0.0000f, 0.4130f);

    b2PolygonShape dynamicBox;
    dynamicBox.Set(verticesLadder1, 4);

    b2Body *ladder1Body = world->CreateBody(&bodyLadder1Def);

    b2FixtureDef fixtureLadder1Def;
    fixtureLadder1Def.shape           = &dynamicBox;
    fixtureLadder1Def.density         = 100.0f;
    fixtureLadder1Def.friction        = 1.0f;
    fixtureLadder1Def.restitution     = 0.5f;
    fixtureLadder1Def.filter.maskBits = 0x0001;

    ladder1Body->CreateFixture(&fixtureLadder1Def);

    // part 2

    b2BodyDef bodyLadder2Def;
    bodyLadder2Def.type = b2_dynamicBody;
    bodyLadder2Def.position.Set(400 / PTM_RATIO, 400 / PTM_RATIO);
    bodyLadder2Def.angularDamping  = 0.5f;
    bodyLadder2Def.linearDamping   = 0.5f;

    b2Vec2 verticesLadder2[4];

    verticesLadder2[0].Set(0.0000f, 0.0000f);
    verticesLadder2[1].Set(3.9560f, 0.0000f);
    verticesLadder2[2].Set(3.9560f, 0.2391f);
    verticesLadder2[3].Set(0.0000f, 0.2391f);

    b2PolygonShape dynamicLadder2Box;
    dynamicLadder2Box.Set(verticesLadder2, 4);

    b2Body *ladder2Body = world->CreateBody(&bodyLadder2Def);

    b2FixtureDef fixtureLadder2Def;
    fixtureLadder2Def.shape           = &dynamicLadder2Box;
    fixtureLadder2Def.density         = 100.0f;
    fixtureLadder2Def.friction        = 1.0f;
    fixtureLadder2Def.restitution     = 0.5f;
    fixtureLadder2Def.filter.maskBits = 0x0001;

    ladder2Body->CreateFixture(&fixtureLadder2Def);

    // joint
    b2PrismaticJointDef prismaticJointDef;
    b2Vec2 worldAxis(1.0f, 0.0f);
    prismaticJointDef.Initialize(ladder1Body, ladder2Body, b2Vec2((400.0f) / PTM_RATIO, (400.0f) / PTM_RATIO), worldAxis);
   
    world->CreateJoint(&prismaticJointDef);

When I run this code on 2.1.0 version of box it works fine. But in version 2.1.2 (and 2.2 now) world sometimes crashes during one body goes through another.
Here are screencasts of program behaviour (an iPad simulator with cocos2d framework)
http://dl.dropbox.com/u/17069366/new_dont_work.swf
http://dl.dropbox.com/u/17069366/old.swf
Is it actually crashing or just moving a lot? If it is crashing, what is the call stack?
It's just moving a lot, cause app continues to work. All objects in world are going away in spite of scene is limited by edgeShapes
Please try this fix:


Command: Commit
Modified: D:\Development\Box2D\Box2D\Box2D\Dynamics\Joints\b2PrismaticJoint.cpp
Sending content: D:\Development\Box2D\Box2D\Box2D\Dynamics\Joints\b2PrismaticJoint.cpp
Completed: At revision: 215
thanks, its ok 😀
Hi again 🙂
I can't understand if it is bug or feature of prismatic joint.

We have a code:
Code:
   
    // cylinder and rootCylinder joint
    b2RevoluteJointDef cylinderJointDef;
    cylinderJointDef.Initialize(cylinderBody, rootCylinder, cylinderBody->GetPosition());
   
    // cylinder and rootCylinder joint   
    b2PrismaticJointDef hydroCylinderJointDef;   
    b2Vec2 axis = cylinderBody->GetPosition() - pistonBody->GetPosition();                       
   
    hydroCylinderJointDef.Initialize(cylinderBody, pistonBody, cylinderBody->GetPosition(), axis);
    hydroCylinderJointDef.lowerTranslation    = -20.0f;
    hydroCylinderJointDef.upperTranslation   = 0.0f;
    hydroCylinderJointDef.enableLimit            = true;
    hydroCylinderJointDef.maxMotorForce      = 10.0f;
    hydroCylinderJointDef.motorSpeed           = 0.0f;
    hydroCylinderJointDef.enableMotor           = true;

    // create joints                                 
    world->CreateJoint(&cylinderJointDef);
    world->CreateJoint(&hydroCylinderJointDef); 
 


Piston starts to twitch, when I try to move piston into cylinder. Screencast

Then we disable limit:
Code:
hydroCylinderJointDef.enableLimit = false;


After that piston can't move through cylinder. Our system just turn round. Screencast
Please call b2World::Dump, zip up the log file, and post the zip file.
log
rav3n wrote:
b2Vec2 axis = cylinderBody->GetPosition() - pistonBody->GetPosition();


This was the problem. You weren't using a unit axis. I added code to normalize the axis.
thanks a lot 😀

Original thread: https://box2d.org/forum/viewtopic.php?t=7544