Adding a note-anchored line to any but the top part/instrument crashes if parts are generated

• Jun 4, 2021 - 12:15
Reported version
3.6
Type
Functional
Frequency
Few
Severity
S2 - Critical
Reproducibility
Always
Status
GitHub issue
Regression
No
Workaround
Yes
Project

In a score with more that one part/intrument, e.g. (Closed Score) SATB + Piano try to add a note-anchored line to notes of the piano staff.


Comments

Title Adding a note-anchored lines to any but the top part crashes Adding a note-anchored lines to any but the top part/instrument crashes
Workaround No Yes

Workaround is to (temporarily) move that part/instrument to the top, prior to adding these lines.
Save, close, reopen before moving the part/instrument back down again, else it crashes too.

Title Adding a note-anchored lines to any but the top part/instrument crashes Adding a note-anchored lines to any but the top part/instrument crashes if parts are generated

I can't reproduce unless parts are generated - same for you?

Also seems to work to add the line first, before generating parts.

Title Adding a note-anchored lines to any but the top part/instrument crashes if parts are generated Adding a note-anchored line to any but the top part/instrument crashes if parts are generated

I removed the piano part and it still crashed. But I left the SATB part(s). If I remove that also it ideed doesn't crash, so there's another workaround (which I'd rather not take in this case, as the parts had a considerable amount of formatting already)

Stack trace:
1 Ms::ScoreElement::score scoreElement.h 189 0x105b59c
2 Ms::Staff::spatium staff.cpp 818 0xac0f60
3 Ms::SLine::linePos line.cpp 776 0xa1779e
4 Ms::SLine::layout line.cpp 1131 0xa19907
5 Ms::Chord::layoutSpanners chord.cpp 2622 0x94ff7c
6 Ms::LayoutContext::collectPage layout.cpp 4967 0xa0bf7f
7 Ms::LayoutContext::layout layout.cpp 5181 0xa0d114
8 Ms::Score::doLayoutRange layout.cpp 5169 0xa0d074
9 Ms::Score::update cmd.cpp 302 0x536488
10 Ms::Score::endCmd cmd.cpp 260 0x536126
11 Ms::ScoreView::cmdAddNoteLine scoreview.cpp 4170 0x6522ed
12 Ms::ScoreView::::operator()(Ms::ScoreView *, const QByteArray &) const scoreview.cpp 2202 0x642b32
13 std::_Function_handler>::_M_invoke(const std::_Any_data &, Ms::ScoreView *&&, const QByteArray &) std_function.h 297 0x65e64b
14 std::function::operator()(Ms::ScoreView *, QByteArray const&) const std_function.h 687 0x10d50ed
15 Ms::ScoreView::cmd scoreview.cpp 2890 0x64ade1
16 Ms::ScoreView::cmd scoreview.cpp 2089 0x6424c7
17 Ms::MuseScore::cmd musescore.cpp 6617 0x433e30
18 Ms::MuseScore::cmd musescore.cpp 6044 0x43077a
19 Ms::MuseScore::qt_static_metacall moc_musescore.cpp 610 0x5eef3d
20 void doActivate(QObject *, int, void * *) 0x68b978bb
...

At level 1 and 2 this is a nullptr

A possible fix seems rather simple, at level 3 of the above stack trace:

$ git diff
diff --git a/libmscore/line.cpp b/libmscore/line.cpp
index 14b994836c..c3af51a4a9 100644
--- a/libmscore/line.cpp
+++ b/libmscore/line.cpp
@@ -773,7 +773,7 @@ SLine::SLine(const SLine& s)
 QPointF SLine::linePos(Grip grip, System** sys) const
       {
       qreal x = 0.0;
-      qreal sp = staff()->spatium(tick());
+      qreal sp = staff() ? staff()->spatium(tick()) : 0.0;
       switch (anchor()) {
             case Spanner::Anchor::SEGMENT:
                   {

The crash doesn't seem to happen in 4.0.2 though

Well, actually not. The line gets added, but then it crashes, when (auto)saving the score, stack trace:
1 Ms::ScoreElement::links scoreElement.h 249 0x105b59c
2 Ms::Element::writeProperties element.cpp 606 0x9a40ab
3 Ms::Spanner::writeProperties spanner.cpp 1318 0xabbc4d
4 Ms::SLine::writeProperties line.cpp 1224 0xa1a153
5 Ms::TextLineBase::writeProperties textlinebase.cpp 526 0xb216fd
6 Ms::TextLine::write textline.cpp 185 0xb1c8c4
7 Ms::ConnectorInfoWriter::write connector.cpp 329 0xbde585
8 Ms::Spanner::writeSpannerStart spanner.cpp 1329 0xabbd52
9 Ms::Note::write note.cpp 1345 0xa40276
10 Ms::Chord::write chord.cpp 1037 0x947e83
11 Ms::Score::writeSegments scorefile.cpp 1364 0xb582be
12 Ms::Measure::write measure.cpp 1992 0xa2c1de
13 Ms::writeMeasure scorefile.cpp 74 0xb500d2
14 Ms::Score::writeMovement scorefile.cpp 245 0xb517fd
15 Ms::Score::write scorefile.cpp 279 0xb51e48
16 Ms::Score::saveFile scorefile.cpp 763 0xb54f46
17 Ms::Score::saveCompressedFile scorefile.cpp 611 0xb53deb
18 Ms::MuseScore::autoSaveTimerTimeout musescore.cpp 5246 0x42bf99
19 Ms::MuseScore::qt_static_metacall moc_musescore.cpp 546 0x5ee6d3
20 void doActivate(QObject *, int, void * *) 0x68b978bb
...

That in turn can get fixed too:

diff --git a/libmscore/element.cpp b/libmscore/element.cpp
index ec3979f070..55507c6b85 100644
--- a/libmscore/element.cpp
+++ b/libmscore/element.cpp
@@ -603,7 +603,7 @@ void Element::writeProperties(XmlWriter& xml) const
                   xml.setLidLocalIndex(_links->lid(), xml.assignLocalIndex(loc));
                   }
             else {
-                  if (s->links()) {
+                  if (s && s->links()) {
                         Staff* linkedStaff = toStaff(s->links()->mainElement());
                         loc.setStaff(linkedStaff->idx());
                         }

This part seems to happen on 4.x too, at least on scores that stem from 3.x? See #343436: Note-anchored line crashes MuseScore on saving