Skip to content

Fix crash during project loading when sample snapping is enabled - #12569

Merged
saintmatthieu merged 1 commit into
audacity:masterfrom
kryksyh:fix-sample-snapping
Oct 28, 2026
Merged

saintmatthieu merged 1 commit into
audacity:masterfrom
kryksyh:fix-sample-snapping

Conversation

@kryksyh

@kryksyh kryksyh commented Oct 23, 2026

Copy link
Copy Markdown
Member

Resolves: #12564

snap formatter was initialized after the first use

  • I signed CLA
  • This PR includes AI assistance
  • If the PR is AI-assisted, I have read, understood and complied with the guidelines for AI-assisted contributions
  • The title of the pull request describes an issue it addresses
  • If changes are extensive, then there is a sequence of easily reviewable commits
  • Each commit's message describes its purpose and effects
  • There are no behavior changes unnecessary for the stated purpose of the PR

Recommended:

  • Each commit compiles and runs on my machine without known undesirable changes of behavior

@kryksyh
kryksyh requested a review from grliszas14 October 23, 2026 12:32
@coderabbitai

coderabbitai Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Important

Review skipped

Review was skipped as selected files did not have any reviewable changes.

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI (base), Organization UI (inherited)
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: fcc49ccb-4777-40bd-bb6a-252ebee9160f
Commits

Reviewing files that changed from the base of the PR and between 87499d9 and 87fe860.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI (base), Organization UI (inherited)
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 36d20974-e6f2-4fdd-a008-aa6dfdea2b81
Commits

Reviewing files that changed from the base of the PR and between a88ca22 and 87499d9.

Files selected for processing: 1
  • src/projectscene/tests/snaptimeformatter_tests.cpp

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

Walkthrough

TimelineContext now constructs its SnapTimeFormatter during object construction instead of in init(). The formatter constructor now accepts a muse::Contextable pointer. Tests cover sample snapping before initialization, guideline visibility, position conversion and single-step behavior at 44,100 Hz, and independent snapping with 44,100 Hz and 48,000 Hz contexts.

Priority: Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Severity of issue fixed: Medium

Merge Risk: Minimal · previous review 87499

The initialization change is covered by focused pre-initialization snapping tests, with no identified merge-blocking risk.

Pre-merge checks: Passed 4
Check name Status Explanation
Title check Passed The title clearly identifies the main change: preventing a crash during project loading when sample snapping is enabled.
Description check Passed The description provides the linked issue, motivation, and required checklist responses. The recommended local-build checkbox is unchecked, but this is non-critical.
Linked Issues check Passed Issue #12564 reports a crash when a project is reopened with snapping to samples enabled. The crash cause is that TimelineContext::init() created m_snapTimeFormatter, so snap calls made before `in…
Out of Scope Changes check Passed The whole-PR diff against the merge base changes only files under src/projectscene. Each file relates to the crash fix for #12564:
- timelinecontext.cpp: moves formatter creation from init() to …
Full details: Linked Issues check

Explanation

Issue #12564 reports a crash when a project is reopened with snapping to samples enabled. The crash cause is that TimelineContext::init() created m_snapTimeFormatter, so snap calls made before init() used a null formatter. At the reviewed head (87499d9), the whole-PR diff against the merge base (6b7f32a) shows these changes:

  • timelinecontext.cpp: m_snapTimeFormatter is now created in the TimelineContext constructor member initializer list, using this. The creation in init() is removed. timelinecontext.h declares m_snapTimeFormatter as std::shared_ptr<SnapTimeFormatter>, so the member exists.
  • snaptimeformatter.h: the constructor now takes const muse::Contextable*. This matches construction from this.
  • snaptestaccess.h: the test wiring no longer creates the formatter. The formatter now comes from TimelineContext construction.
  • snaptimeformatter_tests.cpp: the fixture constructs the formatter with a muse::Contextable.
  • findguideline_tests.cpp: SamplesSnapBeforeInit covers snapping before init(), and SamplesSnapBeforeInit_UsesEachWindowSampleRate covers independent 44,100 Hz and 48,000 Hz contexts.
    The formatter is non-null from construction onward, so the reported crash path is covered. The issue has no non-coding requirements.

Limitations: the build and tests were not run. The muse::Contextable(const Contextable*) overload and any other SnapTimeFormatter constructor callers were not verified in this review. The previous-to-head diff also contains unrelated CI, BUILDING.md, and au3 import changes. These come from base movement and are outside the whole-PR scope.

Full details: Out of Scope Changes check

Explanation

The whole-PR diff against the merge base changes only files under src/projectscene. Each file relates to the crash fix for #12564:

  • timelinecontext.cpp: moves formatter creation from init() to the constructor. This is the fix.
  • snaptimeformatter.h: changes the constructor parameter type to const muse::Contextable*. This is required for construction from this.
  • snaptestaccess.h and snaptimeformatter_tests.cpp: update test construction to the new ownership and signature. These are supporting test changes.
  • findguideline_tests.cpp: adds regression tests for the pre-init and multi-context cases. It also adds test-only includes and a PlayRegionController setup needed by those tests.

The previous-to-head diff shows unrelated CI, documentation, and au3 changes. These are outside the whole-PR diff and are not part of this PR's changes. No unrelated behavior change appears in the whole-PR evidence.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Warning

Linked repositories: Public OSS repositories can only analyze public repositories installed in this organization. No linked repositories were analyzed; skipped musescore/musescore.

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@saintmatthieu
saintmatthieu merged commit 0d8ac4b into audacity:master Oct 28, 2026
3 of 7 checks passed
saintmatthieu added a commit that referenced this pull request Oct 28, 2026
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.

Crash when opening a project with snapping to samples enabled

3 participants