Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged

Conversation

Braykoff
Copy link
Contributor

@Braykoff Braykoff commented Jun 7, 2024

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++.

@Braykoff Braykoff requested a review from a team as a code owner June 7, 2024 23:09
@wpilibsuite wpilibsuite deleted a comment Jun 7, 2024
@Braykoff Braykoff requested a review from calcmogul June 7, 2024 23:55
@PeterJohnson PeterJohnson changed the title Fixes runtime exception thrown by LinearFilter lastValue() [wpimath] Fix runtime exception thrown by LinearFilter lastValue() Jun 8, 2024
@PeterJohnson PeterJohnson merged commit 0606da6 into wpilibsuite:main Jun 8, 2024
24 of 25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants