erincatto / box2d

Box2D is a 2D physics engine for games

Home Page:https://box2d.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Some joints does not check it's input in constructor, but check on future set

DBotThePony opened this issue · comments

The b2RevoluteJoint::SetLimits method check it's input (and b2Assert them):

void b2RevoluteJoint::SetLimits(float lower, float upper)
{
b2Assert(lower <= upper);
if (lower != m_lowerAngle || upper != m_upperAngle)
{
m_bodyA->SetAwake(true);
m_bodyB->SetAwake(true);
m_lowerImpulse = 0.0f;
m_upperImpulse = 0.0f;
m_lowerAngle = lower;
m_upperAngle = upper;
}
}

However, the constructor does not:

b2RevoluteJoint::b2RevoluteJoint(const b2RevoluteJointDef* def)
: b2Joint(def)
{
m_localAnchorA = def->localAnchorA;
m_localAnchorB = def->localAnchorB;
m_referenceAngle = def->referenceAngle;
m_impulse.SetZero();
m_axialMass = 0.0f;
m_motorImpulse = 0.0f;
m_lowerImpulse = 0.0f;
m_upperImpulse = 0.0f;
m_lowerAngle = def->lowerAngle;
m_upperAngle = def->upperAngle;
m_maxMotorTorque = def->maxMotorTorque;
m_motorSpeed = def->motorSpeed;
m_enableLimit = def->enableLimit;
m_enableMotor = def->enableMotor;
m_angle = 0.0f;
}

Same applies to wheel joint

This go sideways with prismatic joint which has similar properties and it check it's input for validity both in constructor and setter:

b2Assert(m_lowerTranslation <= m_upperTranslation);

void b2PrismaticJoint::SetLimits(float lower, float upper)
{
b2Assert(lower <= upper);