Skip to content

Fix score corruption after undoing local time signature deletion - #34845

Open
0xMashiro wants to merge 1 commit into
musescore:mainfrom
0xMashiro:fix/local-timesig-deletion-undo
Open

Fix score corruption after undoing local time signature deletion#34845
0xMashiro wants to merge 1 commit into
musescore:mainfrom
0xMashiro:fix/local-timesig-deletion-undo

Conversation

@0xMashiro

@0xMashiro 0xMashiro commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Resolves: #29789

Deleting a local time signature and undoing restores the visible signature but can leave the full-score staff time-signature map at the preceding meter. Saving then reports an incomplete measure and score corruption.

Register and unregister time signatures when Measure adds or removes a complete time-signature segment. Restoring a segment during undo does not pass through the individual-item registration in Segment::add, so this keeps both mutation paths consistent.

The regression uses the existing timeSig-11.mscz fixture: Clarinet measure 2 has local 7/8 and measure 3 has local 5/4. It covers deletion from the full score and linked part, undo, redo, integrity validation, and MSCZ save/reopen including excerpts.

Validation

  • Unmodified official main a64e0d0c8725a89af2b4b9f8e058a75be20c01d3: the new regression fails. The restored object is 5/4, while the full-score staff lookup remains 7/8; the save integrity check reports incomplete measures.
  • Candidate: all 16 native time signature tests pass (Engraving_TimesigTests.*).
  • Linux desktop, Qt 6.10.2, GCC 14, Debug/ASan: agent-operated delete → undo → save reproduces the corruption warning before the fix and saves successfully after it.
  • Official Uncrustify configuration and git diff --check pass.

Reproduction instructions, scores and native logs

Before video:

local-timesig-before.mp4

After video:

local-timesig-after.mp4

Related work

This addresses the existing report #29789, rather than claiming a newly discovered issue. #26100 provides related local-meter work and the reused fixture. #17418 concerns deleting a whole measure, and #11941 concerns an initial time signature. No matching active fix PR was found in the issue timeline and repository searches; this is not an exhaustive claim about all prior work.

Contributor checklist

  • I signed the CLA. The contributor confirmed signing; the MuseScore.org username remains to be supplied.
  • The title of the PR describes the problem it addresses.
  • Each commit's message describes its purpose and effects, and references the issue it resolves. If changes are extensive, there is a sequence of easily reviewable commits.
  • The code in the PR follows the coding rules.
  • I understand all aspects of the code I'm contributing and I'm able to explain it if requested.
  • The code compiles and runs on my machine, preferably after each commit individually. I have manually tested and verified that my changes fulfil their intended purpose. (Desktop verification was operated by the coding agent.)
  • No prior attempts to resolve this problem exist, or if they do, I listed them in my PR description and described how I avoided repeating past mistakes. (Search scope and related work are described above.)
  • There are no unnecessary changes.
  • I created a unit test or vtest to verify the changes I made (if applicable).

Register and unregister staff time signatures when a complete segment is added or removed. Undo can restore the segment without visiting Segment::add, leaving the restored local meter absent from the staff map.

Add a regression covering deletion from the full score and linked part, undo, redo, score integrity, and MSCZ save/reopen. All 16 native time signature tests pass; the new test fails on the unmodified upstream baseline. Desktop delete/undo/save reproduces the corruption warning before the fix and saves successfully after it.

Resolves: musescore#29789
@0xMashiro
0xMashiro marked this pull request as ready for review September 8, 2026 07:37
@coderabbitai

coderabbitai Bot commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: 6c87e503-decf-4b8a-acdb-ee94234346d8

📥 Commits

Reviewing files that changed from the base of the PR and between a64e0d0 and add1935.

📒 Files selected for processing (2)
  • src/engraving/dom/measure.cpp
  • src/engraving/tests/timesig_tests.cpp

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


📝 Walkthrough

Walkthrough

Measure::add registers each TimeSig in an inserted time-signature segment with its staff. Measure::remove unregisters each TimeSig when the segment is removed. A new test covers local time-signature deletion from scores and excerpts, undo and redo behavior, and persistence after saving and reopening the score.

Priority: ➖ Normal — Impact reflects medium issue severity.

Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to add19

Local time signatures are now registered when restored and unregistered when removed, preventing stale timing state after deletion and undo. The covered score, excerpt, undo/redo, and persistence flows indicate the corruption fix is ready to merge.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The implementation directly addresses issue #29789 by registering and unregistering staff time signatures when complete time-signature segments are added or removed. The regression test covers deletio…
Out of Scope Changes check ✅ Passed The changes are limited to the required Measure time-signature registration logic and focused regression coverage. No unrelated code or test changes are present.
Description check ✅ Passed The description clearly explains the score-corruption bug, the implementation, regression coverage, validation results, related work, and checklist status. The CLA username is not supplied, but the de…
Title check ✅ Passed The title clearly and concisely describes the primary change: fixing score corruption caused by undoing local time signature deletion.
  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

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


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.

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.

Local time signature delete and undo corrupts score

3 participants