-
-
Notifications
You must be signed in to change notification settings - Fork 155
Bug fix: The spectrum graph is sometimes not displayed after change s… #839
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
Merged
haslinghuis
merged 1 commit into
betaflight:master
from
demvlad:spectrum_type_change_issue2
May 31, 2025
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@coderabbitai any reason why dataBuffer could be corrupted ? Can you find any root causes ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Length of output: 8010
@haslinghuis Looking at the codebase, the "corruption" is most likely not actual data corruption but rather a timing/initialization issue. Here's what I found:
Root Cause Analysis
Primary cause: Uninitialized state, not corruption
The
dataBufferis initialized withcurve: null:The
curveproperty is only set whenplotSpectrum()is called:The issue occurs when:
dataBuffer.curveis stillnull(its initial value)!dataBuffer.curveand assumes "corruption"GraphSpectrumCalc._dataBufferwhich should have valid dataWhy This Happens
From my analysis, there are no other code paths that reset or corrupt
dataBuffer. The check is essentially a defensive measure against this timing scenario:plotSpectrum()hasn't been called yet, socurveis stillnullThis is good defensive programming - it ensures the spectrum analyzer can recover even when users interact with controls before the initial data load completes.
Alternative scenarios (less likely):
plotSpectrum()from being calledThe current fix is appropriate as it provides a safety net for these edge cases.
🧬 Code Graph Analysis Results
Relevant snippets from
src/graph_spectrum_calc.js(lines 24-38, 182-190, 478-485)Summary:
The
GraphSpectrumCalcobject holds internal state including_dataBufferwhich containsfieldIndex,curve, andfieldName. ThefftDataobjects returned by various data loading functions include references to these_dataBufferfields. This suggests thatdataBufferinFlightLogAnalyseris linked toGraphSpectrumCalc._dataBuffer. Corruption ofdataBuffercould be related to how_dataBufferis managed or updated insideGraphSpectrumCalc.Relevant snippet from
src/graph_spectrum.js(lines ~150-190)Summary:
dataBufferis a local object inFlightLogAnalyserthat stores the current field index, curve, and field name. It is updated inplotSpectrum. When the spectrum type changes, ifdataBuffer.curveis falsy (indicating possible corruption or reset), it is restored fromGraphSpectrumCalc._dataBuffer. This indicates thatdataBuffercan become corrupted or reset, and the code attempts to recover it from the internal_dataBufferofGraphSpectrumCalc.Relevant snippet from
src/pref_storage.js(lines 6-63)Summary:
PrefStorageis used inFlightLogAnalyserto save and retrieve user settings asynchronously. This could indirectly affectdataBufferif user settings influence data loading or spectrum type, but it does not directly manipulatedataBuffer.Relevant snippet from
src/spectrum-exporter.js(lines 13-42)Summary:
SpectrumExporterusesfftDatato export spectrum data asynchronously via a web worker. This relates tofftDatabut does not directly affectdataBuffer.Relevant snippet from
src/graph_spectrum_plot.js(lines 31-51)Summary:
GraphSpectrumPlotholds internal state related to the spectrum plot including_fftData. This is set inFlightLogAnalyserafter data loading. It does not directly manipulatedataBufferbut is part of the data flow.Summary of relevant context for
dataBuffercorruption:dataBufferinFlightLogAnalyseris a local object holding references to the current field index, curve, and field name.plotSpectrumand used to load data viaGraphSpectrumCalc.GraphSpectrumCalchas an internal_dataBufferwith similar structure.dataBuffer.curveis falsy (indicating corruption or reset), it is restored fromGraphSpectrumCalc._dataBuffer.dataBuffercorruption could be related to howGraphSpectrumCalc._dataBufferis managed or howplotSpectrumis called.dataBufferoutside the spectrum type change event.PrefStoragemay indirectly affect data loading anddataBuffer.fftDataobject returned fromGraphSpectrumCalcfunctions references_dataBufferfields, linking the data flow.This context is relevant to investigate potential root causes of
dataBuffercorruption insrc/graph_spectrum.js.