In class OpenSim::PiecewiseLinearFunction, when the number of function points was equal to one (i.e., when _x.getSize() == 1) initialization of the coefficient array, _b, was getting skipped. In such a situation, when calcValue() was called (sill a valid thing to do!), _b[0] was being accessed when the size of _b was still 0 (an access violation) and would often produce a spurious result.
In a Release build, the above access violation was causing sporadic failures in the testPrescribedForce unit test.
In a Debug build, testPrescribedForce always failed because of an array out-of-bounds error detected by a low-level assert.
Brief summary of changes
Added/Altered ~6 lines of code in PiecewiseLinearFunction::calcCoefficients() to properly size and initialize _b when n == 1. See lines 417 - 425 of PiecewiseLinearFunction.cpp.
Testing I've completed
In both Debug and Release builds, the testPrescribedForce unit test is now passing. In addition, all other unit tests pass in a Release build. (Note that there continue to be quite a few unit tests that do not pass in a Debug build for unrelated reasons.)
Fixes issue #3816
In class
OpenSim::PiecewiseLinearFunction
, when the number of function points was equal to one (i.e., when_x.getSize() == 1
) initialization of the coefficient array,_b
, was getting skipped. In such a situation, whencalcValue()
was called (sill a valid thing to do!),_b[0]
was being accessed when the size of_b
was still0
(an access violation) and would often produce a spurious result.In a
Release
build, the above access violation was causing sporadic failures in thetestPrescribedForce
unit test.In a
Debug
build,testPrescribedForce
always failed because of an array out-of-bounds error detected by a low-level assert.Brief summary of changes
Added/Altered ~6 lines of code in
PiecewiseLinearFunction::calcCoefficients()
to properly size and initialize_b
whenn == 1
. See lines 417 - 425 ofPiecewiseLinearFunction.cpp
.Testing I've completed
In both
Debug
andRelease
builds, thetestPrescribedForce
unit test is now passing. In addition, all other unit tests pass in aRelease
build. (Note that there continue to be quite a few unit tests that do not pass in aDebug
build for unrelated reasons.)CHANGELOG.md (choose one)
This change is