Skip to content

Fix off-by-one that leaves one stale point in the graph buffer#580

Open
chatman-media wants to merge 1 commit into
orf:masterfrom
chatman-media:fix/plot-buffer-trim-off-by-one
Open

Fix off-by-one that leaves one stale point in the graph buffer#580
chatman-media wants to merge 1 commit into
orf:masterfrom
chatman-media:fix/plot-buffer-trim-off-by-one

Conversation

@chatman-media

Copy link
Copy Markdown

PlotData::update trims points older than the buffer window by finding the index of the last stale entry and draining 0..idx. But idx itself matched the "is stale" filter, so it never actually gets removed — every call leaves exactly one out-of-window point sitting in data. It's subtle since it's always just one point and gets re-evaluated on the next tick, but it means the graph (and the min/max bounds computed from it) is never quite trimmed to what --buffer says it should be.

Changed the drain to 0..=idx and added a test that seeds a mix of stale/fresh timestamps directly and checks none of the stale ones survive update().

drain(0..idx) skips the element at idx, but idx is the index of the last
point that's actually older than the buffer window (it matched the filter
right above). So every update() call quietly leaves exactly one out-of-window
sample sitting in the data, forever. Switched it to drain(0..=idx) and added
a test that seeds a few stale/fresh points and checks nothing older than the
window survives after update().
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.

1 participant