Skip to content

Fix assert on broken slurs#34041

Open
miiizen wants to merge 3 commits into
musescore:mainfrom
miiizen:mu2SlurAssert
Open

Fix assert on broken slurs#34041
miiizen wants to merge 3 commits into
musescore:mainfrom
miiizen:mu2SlurAssert

Conversation

@miiizen

@miiizen miiizen commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Some MU2 files contain lots of corrupt slurs with starts and no ends. These should be removed from the score after reading the file.

There is also a commit fixing a use after free error. Spanner::setStart/EndElement didn't update pointers to the spanner which could be held by a Chord.

@miiizen miiizen requested review from alexpavlov96 and mike-spa July 2, 2026 13:19
@coderabbitai

coderabbitai Bot commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Review 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: Pro

Run ID: 5c604133-ca8a-445c-80ab-13e679409320

📥 Commits

Reviewing files that changed from the base of the PR and between 9a374a8 and c138d03.

📒 Files selected for processing (2)
  • src/engraving/dom/spanner.cpp
  • src/engraving/rw/read206/read206.cpp
💤 Files with no reviewable changes (2)
  • src/engraving/rw/read206/read206.cpp
  • src/engraving/dom/spanner.cpp

📝 Walkthrough

Walkthrough

This change routes Spanner anchor updates through setStartElement() and setEndElement(), and those setters now keep chord-side spanner lists in sync when anchors change. The compute* and anchor-accessor paths in spanner.cpp were updated to use the setters consistently. Legacy score reading now removes invalid slur spanners, and MusicXML import clears temporary slur anchors before deleting same-chord fallback slurs.

Changes

Cohort / File(s) Summary
src/engraving/dom/spanner.cpp Centralized start/end anchor updates through the setter methods and updated compute/accessor paths to use them.
src/engraving/rw/read206/read206.cpp Added cleanup for invalid slur spanners during legacy score reading.
src/importexport/musicxml/internal/import/importmusicxmlpass2.cpp Cleared temporary slur anchors before deleting them in same-chord and invalid-tick branches.

Sequence Diagram(s)

Diagrams are included above in the hidden review stack artifact.

Related issues: Not specified.

Related PRs: Not specified.

Suggested labels: engraving, import, bug-fix

Suggested reviewers: Not specified.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description is on-topic but misses the required template sections, issue reference, and checklist items. Add a Resolves #NNNN line, a brief change summary, and complete the required checklist items from the template.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly matches the main change: fixing issues caused by broken slurs.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

Review ran into problems

🔥 Problems

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
src/importexport/musicxml/internal/import/importmusicxmlpass2.cpp (1)

8338-8341: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Consider routing cleanup through setEndElement/setStartElement for consistency with the centralized registration pattern.

These three cleanup sites manually call Chord::removeEndingSpanner/removeStartingSpanner directly, duplicating logic that Spanner::setEndElement(nullptr)/setStartElement(nullptr) already perform (per the cohort's centralization of chord anchor registration in spanner.cpp). Calling newSlur->setEndElement(nullptr) / newSlur->setStartElement(nullptr) before delete would achieve the same cleanup while staying consistent with the new architecture and avoiding direct coupling to Chord's internal spanner-set API from this file.

Spanner::setStartElement/setEndElement remove the spanner from the old chord's starting/ending spanner sets and add it to the new chord's corresponding sets. This is exactly the behavior being manually re-implemented here.

Based on the review-stack context describing the intent to centralize anchor registration through the setters (Cohort: "Spanner anchor registration refactor"), this file's direct calls bypass that centralization.

Also applies to: 8350-8353, 8401-8404

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/importexport/musicxml/internal/import/importmusicxmlpass2.cpp` around
lines 8338 - 8341, The cleanup code for `newSlur` is bypassing the centralized
spanner anchor management by calling
`Chord::removeEndingSpanner`/`removeStartingSpanner` directly. Update the
affected cleanup paths in `importmusicxmlpass2.cpp` to clear anchors via
`Spanner::setEndElement(nullptr)` and `Spanner::setStartElement(nullptr)` on
`newSlur` before deletion, so the existing registration/removal logic in
`spanner.cpp` is used consistently. Keep the behavior the same for all listed
cleanup sites while removing the direct `Chord` coupling.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@src/importexport/musicxml/internal/import/importmusicxmlpass2.cpp`:
- Around line 8338-8341: The cleanup code for `newSlur` is bypassing the
centralized spanner anchor management by calling
`Chord::removeEndingSpanner`/`removeStartingSpanner` directly. Update the
affected cleanup paths in `importmusicxmlpass2.cpp` to clear anchors via
`Spanner::setEndElement(nullptr)` and `Spanner::setStartElement(nullptr)` on
`newSlur` before deletion, so the existing registration/removal logic in
`spanner.cpp` is used consistently. Keep the behavior the same for all listed
cleanup sites while removing the direct `Chord` coupling.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 22e1aea5-3f47-4211-83ea-06a51b176501

📥 Commits

Reviewing files that changed from the base of the PR and between be04133 and afc8886.

📒 Files selected for processing (2)
  • src/engraving/dom/spanner.cpp
  • src/importexport/musicxml/internal/import/importmusicxmlpass2.cpp
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/engraving/dom/spanner.cpp

miiizen added 3 commits July 8, 2026 07:30
When setting m_startElement and m_endElement directly, we do not update references to the spanner in m_starting/endingSpanners
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.

2 participants