b2WheelJoint uninitialized variable

General Box2D issues or C++ specific issues
Wurst
Posts: 2
Joined: Sun Apr 02, 2017 4:24 am

b2WheelJoint uninitialized variable

Postby Wurst » Sun Apr 02, 2017 4:31 am

I found a case where two member variables of b2WheelJoint remain uninitialized.

In the case of m_frequencyHz = 0.0f the members m_sAx and m_sBx are not set in InitVelocityConstraints() but are used in SolveVelocityConstraints() which leads to undefined behavior usually resulting in NANs in the system.

Setting m_sAx and m_sBx to 0.0f in the constructor resolves the problem.

Louis Langholtz
Posts: 20
Joined: Tue Dec 20, 2016 10:53 am

Re: b2WheelJoint uninitialized variable

Postby Louis Langholtz » Wed Apr 12, 2017 10:10 pm

Nice find!

What about m_ax? Looks like that could be used uninitialized too in the 0 frequency case.

Also, what if the user creates the joint with a frequency and then later changes that frequency to zero? I don't think setting m_sAx and m_sBx to 0.0f in the constructor will work in that case. They may not be NaN then but they might also not be 0 then. I suspect m_sAx and m_sBx need to be set to 0 in the InitVelocityConstraints() method in this case, or in the SetSpringFrequencyHz() method. Same with the m_ax variable.

Wurst
Posts: 2
Joined: Sun Apr 02, 2017 4:24 am

Re: b2WheelJoint uninitialized variable

Postby Wurst » Tue May 09, 2017 12:05 pm

m_ax is already set to zero in the constructor, but you are right, all three should be set to zero in the else-branch of "if (m_frequencyHz > 0.0f)" so that no random values remain when resetting m_frequencyHz to zero without recreating the object.


Return to “Bugs, Requests, and Feedback”



Who is online

Users browsing this forum: No registered users and 1 guest