Fix spectrum-strip peak-block crash when bin count grows between frames#496
Open
patrickrb wants to merge 1 commit into
Open
Fix spectrum-strip peak-block crash when bin count grows between frames#496patrickrb wants to merge 1 commit into
patrickrb wants to merge 1 commit into
Conversation
…frames ColumnarView.setWaveData rebuilt the peak-hold "falling block" list to the CURRENT frame's bin count (binsToShow) but the fall loop read positions from the PREVIOUS frame's bar list (newData). When the visible bin count grew between two frames — a spectrum-width change (NumberInputDialog, 2500-5000 Hz) or an audio-sample-rate change while the peak blocks are shown — the loop indexed past the previous bars and threw IndexOutOfBoundsException. Drawing runs on the UI thread with no try/catch, so that is a hard app crash. Root cause: the rebuild sized to binsToShow while the copy source (newData) still held the previous frame's, smaller, bar set. Fix: drive the peak-hold state off the bars actually present this frame. The geometry/sizing decision is extracted into a pure, JVM-testable PeakBlocks helper (mirroring the BinAggregation extraction) that always returns one block per current bar; a bin-count change resets the peak-hold to the floor, matching the legacy full-rebuild. When the bin count is unchanged the geometry is bit-for-bit identical to the pre-fix code. Tests: PeakBlocksTest covers the growing-bin-count crash (asserts the legacy inline logic throws and the fix does not), first-frame/rise/fall math, the shrinking-bin-count reset, and bit-for-bit parity with the legacy math for the stable-size case. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #496 +/- ##
=========================================
Coverage 23.35% 23.35%
Complexity 162 162
=========================================
Files 167 167
Lines 21450 21450
Branches 3154 3154
=========================================
Hits 5009 5009
Misses 16248 16248
Partials 193 193
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
ColumnarView(the spectrum strip's bar view) can throw anIndexOutOfBoundsExceptionon the UI thread — an unrecoverable app crash —while drawing the peak-hold "falling block" overlay. This fixes the root cause
and adds tests.
Root cause
In
ColumnarView.setWaveData(int[])the peak-block section rebuilt its blocklist to the current frame's bin count (
binsToShow) whenever the sizechanged:
but the copy loop reads geometry from
newData, which at that point stillholds the previous frame's (smaller) bar set —
newDatais not rebuiltuntil later in the method. When the visible bin count grows between two
frames, the loop indexes past the previous bars →
IndexOutOfBoundsException.Drawing is not wrapped in try/catch, so it crashes the app.
The bin count changes whenever
binsToShow = min(len, round(spectrumWidth / nyquist * len))changes — i.e. on a spectrum-width change (theNumberInputDialog, 2500–5000 Hz, in Radio/Audio settings) or an audiosample-rate change — both reachable at runtime while the peak blocks are
shown (
setShowBlock(true)is set on the waterfall'sColumnarView).Fix
Drive the peak-hold state off the bars actually present this frame. The
sizing/geometry decision is extracted into a pure, JVM-testable
PeakBlockshelper (mirroring the existing
BinAggregationextraction). It always returnsexactly one block per current bar, so the copy can never over-index. A
bin-count change resets the peak-hold to the floor (matching the legacy
full-rebuild); when the count is unchanged the geometry is bit-for-bit
identical to the pre-fix code. The
Composable/Viewwrapper stays a thincaller, per the project's testability guidance.
Testing
PeakBlocksTest(pure JVM, no Robolectric):growingBinCountDoesNotThrow— asserts the reconstructed legacy inlinelogic throws on a grown bin count and the fix does not.
stableSizeMatchesLegacyMath— bit-for-bit parity with the legacy mathwhen the size is unchanged.
reset, empty-bars cases.
./gradlew :app:testDebugUnitTest— full suite green../gradlew :app:assembleDebug— native cpp + APK build succeeds.Risk
Low and localized to
ColumnarView's peak-block overlay. No DSP, decoder,encoder, protocol, or CAT behavior touched. Steady-state rendering is
unchanged (verified by the parity test); only the previously-crashing
size-change transient now renders instead of throwing. Same per-frame
Rectreuse as before, so no allocation/perf regression.
🤖 Generated with Claude Code