erincatto / box2d

Box2D is a 2D physics engine for games
https://box2d.org
MIT License
8.05k stars 1.51k forks source link

b2DistanceJoint::Draw initializes length variable but never uses it #694

Closed cugone closed 2 years ago

cugone commented 3 years ago

I compile all projects in Warning Level 4 with treat warnings as errors turned on. The following function returns a warning as an error where the variable length is initialized but never used.

void b2DistanceJoint::Draw(b2Draw* draw) const
{
        const b2Transform& xfA = m_bodyA->GetTransform();
        const b2Transform& xfB = m_bodyB->GetTransform();
        b2Vec2 pA = b2Mul(xfA, m_localAnchorA);
        b2Vec2 pB = b2Mul(xfB, m_localAnchorB);

        b2Vec2 axis = pB - pA;

        //`length` variable is initialized but never used!
        float length = axis.Normalize();

        b2Color c1(0.7f, 0.7f, 0.7f);
        b2Color c2(0.3f, 0.9f, 0.3f);
        b2Color c3(0.9f, 0.3f, 0.3f);
        b2Color c4(0.4f, 0.4f, 0.4f);

        draw->DrawSegment(pA, pB, c4);

        b2Vec2 pRest = pA + m_length * axis;
        draw->DrawPoint(pRest, 8.0f, c1);

        if (m_minLength != m_maxLength)
        {
                if (m_minLength > b2_linearSlop)
                {
                        b2Vec2 pMin = pA + m_minLength * axis;
                        draw->DrawPoint(pMin, 4.0f, c2);
                }

                if (m_maxLength < FLT_MAX)
                {
                        b2Vec2 pMax = pA + m_maxLength * axis;
                        draw->DrawPoint(pMax, 4.0f, c3);
                }
        }
}