Skip to content

Conversation

@demvlad
Copy link
Contributor

@demvlad demvlad commented Jun 7, 2025

The continue of #837 #838 #839 PRs.
The last #839 PR has not full the random dataBuffer destroing bug prevention
There is no dataBuffer, there is no this bug by using this PR

Summary by CodeRabbit

  • Refactor
    • Improved data buffer management for spectrum graphs, reducing reliance on global state and enhancing stability when switching spectrum types. No visible changes to the user interface or workflow.
  • Chores
    • Updated internal methods for handling spectrum data to use explicit parameter passing.

@coderabbitai
Copy link

coderabbitai bot commented Jun 7, 2025

## Walkthrough

The changes refactor how spectrum data buffers are managed by removing reliance on a global `dataBuffer` object. Functions now explicitly pass `fieldIndex`, `curve`, and `fieldName` as parameters. The logic for restoring or mutating a global data buffer was eliminated, and related function signatures and calls were updated accordingly.

## Changes

| File(s)                | Change Summary                                                                                          |
|-----------------------|--------------------------------------------------------------------------------------------------------|
| src/graph_spectrum.js  | Refactored `dataLoad` to accept explicit parameters; updated calls in `plotSpectrum` and event handlers; removed global `dataBuffer` logic. |
| src/graph_spectrum_calc.js | Changed `GraphSpectrumCalc.setDataBuffer` to accept three parameters instead of a single object.        |

## Sequence Diagram(s)

```mermaid
sequenceDiagram
    participant UI
    participant FlightLogAnalyser
    participant GraphSpectrumCalc

    UI->>FlightLogAnalyser: plotSpectrum(fieldIndex, curve, fieldName)
    FlightLogAnalyser->>GraphSpectrumCalc: setDataBuffer(fieldIndex, curve, fieldName)
    GraphSpectrumCalc-->>FlightLogAnalyser: (updates internal buffer)
    FlightLogAnalyser-->>UI: (renders spectrum plot)

Possibly related PRs

Suggested labels

RN: BUGFIX

Suggested reviewers

  • haslinghuis

<!-- walkthrough_end -->


---

<details>
<summary>📜 Recent review details</summary>

**Configuration used: .coderabbit.yaml**
**Review profile: CHILL**
**Plan: Pro**


<details>
<summary>📥 Commits</summary>

Reviewing files that changed from the base of the PR and between 3deeff1713205511ea8b3b3cdf6112caf1b1f950 and 71e3bbcf80a453574e7a56376df4c81b5235d686.

</details>

<details>
<summary>📒 Files selected for processing (1)</summary>

* `src/graph_spectrum.js` (4 hunks)

</details>

<details>
<summary>🔇 Additional comments (3)</summary><blockquote>

<details>
<summary>src/graph_spectrum.js (3)</summary>

`98-101`: **Excellent refactoring to eliminate mutable shared state.**

The parameterized `dataLoad` function with conditional `GraphSpectrumCalc.setDataBuffer` call is a clean solution that should effectively prevent the dataBuffer corruption bug mentioned in the PR objectives. The explicit parameter passing improves code clarity and eliminates implicit dependencies.

---

`130-130`: **Consistent parameter passing implementation.**

The explicit parameter passing to `dataLoad` aligns perfectly with the new function signature and maintains data flow transparency.

---

`203-203`: **Simplified spectrum type change handling.**

The call to `plotSpectrum(-1, null, null)` effectively refreshes FFT data without relying on the problematic dataBuffer restoration logic, which should eliminate the random spectrum type change bug.

</details>

</blockquote></details>

</details>
<!-- internal state start -->


<!-- DwQgtGAEAqAWCWBnSTIEMB26CuAXA9mAOYCmGJATmriQCaQDG+Ats2bgFyQAOFk+AIwBWJBrngA3EsgEBPRvlqU0AgfFwA6NPEgQAfACgjoCEYDEZyAAUASpETZWaCrKNxU3bABsvkCiQBHbGlcABpIcVwvOkgAIhsSZnwpegduSgAzL2x8bGRaajQAIWwMjMoULCIqblgAfUR0sQpHCPwefykMXAjYEj9MWhZ7JtwW5gjZdMZYTFJIAWwiUNjIAHc0ZAcBZnUaejle/ryKpWYJLzR6Tes7DEcBCoAOABYARkqjhZJcNCz4IiwXAAegElwYAGsBPgAB5gLz4IhgCTwEhrCr+bj4RDqfAuDQwPq3BTdeD3aRfNZ4iGQDIUYa8Ego3LIfyXfa3ZBmJ4AZgA7OFuTynuFBpAhQBOAlwfpKRAMCjwbjifBYDD4GjIXCzHra/qXRA9WyQAAUkoAlJBaPB6OqehlvF55IyurqiVQMEMJgVfiUyqcQi0xPBVQslqL8kgGHlEDEyegsEgHP0mKx2JAvGSIXGsHqrdIFUqVRhpQhkNGKP5usSrrR/IhY1qibxBNEJod/EkURgiF9sBhyAxpIhnPIfcVSuU+PG89U0LUGqNxgpmFjyN1wmsEAxYJ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8jMwMD3KSZ8+ZRHzWLMgdE/hIC6SUKrJI1onqfksegGxZIMEHTOgVYqAIgQVSIFVA6shapDUuqBVqKBVxtnYPw1U5EvKxAolZGydkHL1DTuMOoV9SZuQ8okrh/kgpKVYjEBw4V5D0Qge+RAcV+gNRGg9bG848YE27iTMmPwqbHUHhPRxdNURXg0RNfo6hkBkITvYAER5cDYBsdNc6OIexoJdg+Oa8cfgVCwU7EkvwyRMJbOkGRVsRZzL+t9SWL1pYQ3hoDS5TMlAs2vNqfw/RYxkJoOs8hsMuAMxem9R5/0fpnJueLP5oNwbxRnu1Cg1UnQl3qetUC58tKbBxEQDATZpD9AmZsxOVp4D+DECjZ5RImCVmkGua091DmUHEObBiBV+7UwPmlB8qsGnFkif4WZsLIBH2yP0Ts2hMUPX7EoJ65AQ6llQJoiCvDYb5wvl8TlyLZVoxiGKZCWl6EeDRTma8ftFg9CGBSO06B/QZTzB4jqXiERVyMY8WQqp6C4oof2KGkJqEcPMNwhV4jVTaOEaIMRcTRVVKkbomIcjsAKKMUo+ltSDBQAALI/H1lMjF1A5nHG4GbWgvzmm1DvkTDp5NulNynCafelAP6QEAEmETSO5tJ7qTctLLKAmnuQCj64RRbhHudcut8Z4qpPsjjRc2tHDZI6W5eKnlvLJvMpZGiCMqmQUUixFSMR2LsC4FQLS5TdIRUEooIyagTISWXVJFcuxcB1BtIgOoZc0R0AaL8GRZkLI3p5EoEgZQ3h8jeDyAATAABgAKwQbeG8DmTwBA8gQwwWgGQABsMGQOfgyG8AQbwMgSgg2Br9Bgb1AZIIhgQDAMhPDA2gF4EGeQQb5C8EgfI0AQdQ/yVDKGXgMCeDhiDIHGO0FQ08VDxGSPUVveoB9tAn0vvRLQOotEv1AA== -->

<!-- internal state end -->
<!-- finishing_touch_checkbox_start -->

<details open="true">
<summary>✨ Finishing Touches</summary>

- [ ] <!-- {"checkboxId": "7962f53c-55bc-4827-bfbf-6a18da830691"} --> 📝 Generate Docstrings

</details>

<!-- finishing_touch_checkbox_end -->
<!-- tips_start -->

---

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

<details>
<summary>❤️ Share</summary>

- [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai)
- [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai)
- [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai)
- [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code)

</details>

<details>
<summary>🪧 Tips</summary>

### Chat

There are 3 ways to chat with [CodeRabbit](https://coderabbit.ai?utm_source=oss&utm_medium=github&utm_campaign=betaflight/blackbox-log-viewer&utm_content=841):

- Review comments: Directly reply to a review comment made by CodeRabbit. Example:
  - `I pushed a fix in commit <commit_id>, please review it.`
  - `Explain this complex logic.`
  - `Open a follow-up GitHub issue for this discussion.`
- Files and specific lines of code (under the "Files changed" tab): Tag `@coderabbitai` in a new review comment at the desired location with your query. Examples:
  - `@coderabbitai explain this code block.`
  -	`@coderabbitai modularize this function.`
- PR comments: Tag `@coderabbitai` in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
  - `@coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.`
  - `@coderabbitai read src/utils.ts and explain its main purpose.`
  - `@coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.`
  - `@coderabbitai help me debug CodeRabbit configuration file.`

### Support

Need help? Create a ticket on our [support page](https://www.coderabbit.ai/contact-us/support) for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

### CodeRabbit Commands (Invoked using PR comments)

- `@coderabbitai pause` to pause the reviews on a PR.
- `@coderabbitai resume` to resume the paused reviews.
- `@coderabbitai review` to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
- `@coderabbitai full review` to do a full review from scratch and review all the files again.
- `@coderabbitai summary` to regenerate the summary of the PR.
- `@coderabbitai generate docstrings` to [generate docstrings](https://docs.coderabbit.ai/finishing-touches/docstrings) for this PR.
- `@coderabbitai generate sequence diagram` to generate a sequence diagram of the changes in this PR.
- `@coderabbitai resolve` resolve all the CodeRabbit review comments.
- `@coderabbitai configuration` to show the current CodeRabbit configuration for the repository.
- `@coderabbitai help` to get help.

### Other keywords and placeholders

- Add `@coderabbitai ignore` anywhere in the PR description to prevent this PR from being reviewed.
- Add `@coderabbitai summary` to generate the high-level summary at a specific location in the PR description.
- Add `@coderabbitai` anywhere in the PR title to generate the title automatically.

### Documentation and Community

- Visit our [Documentation](https://docs.coderabbit.ai) for detailed information on how to use CodeRabbit.
- Join our [Discord Community](http://discord.gg/coderabbit) to get help, request features, and share feedback.
- Follow us on [X/Twitter](https://twitter.com/coderabbitai) for updates and announcements.

</details>

<!-- tips_end -->

coderabbitai[bot]
coderabbitai bot previously approved these changes Jun 7, 2025
@sonarqubecloud
Copy link

sonarqubecloud bot commented Jun 7, 2025

@github-actions
Copy link

github-actions bot commented Jun 7, 2025

Preview URL: https://71e3bbcf.betaflight-blackbox.pages.dev

@demvlad
Copy link
Contributor Author

demvlad commented Jun 7, 2025

@coderabbitai
is this solution better then #839 ?

@coderabbitai
Copy link

coderabbitai bot commented Jun 7, 2025

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Get information about PR #839 to compare with current PR #841
gh pr view 839 --json title,body,url

Length of output: 1215


🏁 Script executed:

#!/bin/bash
# Get the files changed in PR #839
gh pr diff 839 --name-only

Length of output: 77


🏁 Script executed:

#!/bin/bash
# Get the actual diff for PR #839 to understand the changes
gh pr diff 839

Length of output: 2823


@demvlad Yes, this solution (PR #841) is significantly better than #839. Here's why:

Fundamental Approach Difference

PR #839 (Reactive Fix):

  • Keeps the problematic dataBuffer shared state
  • Adds corruption detection logic
  • Tries to restore corrupted data from backup
  • Treats the symptom, not the root cause

PR #841 (Proactive Fix):

  • Eliminates the dataBuffer shared state entirely
  • Uses explicit parameter passing
  • Prevents corruption from occurring in the first place
  • Addresses the root cause

Why PR #841 is Superior

  1. Root Cause Elimination: Instead of detecting and fixing corruption after it happens, this PR prevents it entirely by removing the mutable shared state that was causing the issue.

  2. Simpler Logic: No need for corruption detection, backup/restore mechanisms, or special handling of null values. The code is cleaner and more straightforward.

  3. Better Architecture: Explicit parameter passing is a more robust pattern than relying on shared mutable state, making the code more predictable and easier to debug.

  4. Long-term Maintainability: Future developers won't have to understand the complex corruption detection logic from Bug fix: The spectrum graph is sometimes not displayed after change s… #839.

  5. Performance: Eliminates the overhead of corruption checks and data restoration.

The trade-off is that PR #841 is more invasive to the existing API, but this is a worthwhile change for the improved reliability and maintainability it provides. As you noted in the PR description, PR #839 "did not fully prevent the random dataBuffer destruction bug" - this confirms that the band-aid approach wasn't sufficient, making the more thorough fix in PR #841 the right choice.

@haslinghuis haslinghuis added this to the 4.0.0 milestone Jun 7, 2025
@haslinghuis haslinghuis merged commit 318cc75 into betaflight:master Jun 9, 2025
5 checks passed
@demvlad demvlad deleted the spectrum_type_change_issue3 branch September 17, 2025 13:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants