wpilibsuite / allwpilib

Official Repository of WPILibJ and WPILibC
https://wpilib.org/
Other
1.03k stars 607 forks source link

[wpimath] Fix runtime exception thrown by LinearFilter lastValue() #6713

Closed Braykoff closed 3 weeks ago

Braykoff commented 3 weeks ago

The current implementation of LinearFilter's lastValue() method causes a runtime exception when the size of the output gains buffer is 0, such as with a Moving Average Filter. In this case, outputs are not added to the buffer, and attempting to get the last value throws an index out-of-bounds exception. This behavior is not documented anywhere.

This fixes this issue by saving the last calculated value to a member variable and returning that when lastValue() is called, in both Java and C++.