Skip to content

Commit

Permalink
Fix #306917: Crash on tie in score with parts
Browse files Browse the repository at this point in the history
Resolves: https://musescore.org/en/node/306917.

Apply the same method from https:://github.com//pull/6049 in undoAddElement() for determining the tracks in which to place new elements.
  • Loading branch information
mattmcclinch committed Jun 21, 2020
1 parent 0098c22 commit 3a8bdf1
Showing 1 changed file with 37 additions and 13 deletions.
50 changes: 37 additions & 13 deletions libmscore/edit.cpp
Expand Up @@ -4532,17 +4532,48 @@ void Score::undoAddElement(Element* element)
return;
}

// For linked staves the length of staffList is always > 1 since the list contains the staff itself too!
const bool linked = ostaff->staffList().length() > 1;

for (Staff* staff : ostaff->staffList()) {
Score* score = staff->score();
int staffIdx = staff->idx();

QList<int> tr;
if ((strack & ~3) != staffIdx) // linked staff ?
tr.append(staffIdx * VOICES + (strack % VOICES));
else if (staff->score()->excerpt() && strack > -1)
tr = staff->score()->excerpt()->tracks().values(strack);
else
tr.append(strack);
if (!staff->score()->excerpt()) {
// On masterScore.
int track = staff->idx() * VOICES + (strack % VOICES);
tr.append(track);
}
else {
QMultiMap<int, int> mapping = staff->score()->excerpt()->tracks();
if (mapping.isEmpty()) {
// This can happen during reading the score and there is
// no Tracklist tag specified.
// TODO solve this in read301.cpp.
tr.append(strack);
}
else {
for (int track : mapping.values(strack)) {
// linkedPart : linked staves within same part/instrument.
// linkedScore: linked staves over different scores via excerpts.
const bool linkedPart = linked && (staff != ostaff) && (staff->score() == ostaff->score());
const bool linkedScore = linked && (staff != ostaff) && (staff->score() != ostaff->score());
if (linkedPart && !linkedScore) {
tr.append(staff->idx() * VOICES + mapping.value(track));
}
else if (!linkedPart && linkedScore) {
if ((track >> 2) != staffIdx)
track += (staffIdx - (track >> 2)) * VOICES;
tr.append(track);
}
else {
tr.append(track);
}
}
}
}


// Some elements in voice 1 of a staff should be copied to every track which has a linked voice in this staff

Expand All @@ -4565,13 +4596,7 @@ void Score::undoAddElement(Element* element)
tr.append(staffIdx * VOICES);
}

int it = 0;
for (int ntrack : tr) {
if ((ntrack & ~3) != staffIdx * VOICES) {
it++;
continue;
}

Element* ne;
if (staff == ostaff)
ne = element;
Expand Down Expand Up @@ -4880,7 +4905,6 @@ void Score::undoAddElement(Element* element)
}
else
qWarning("undoAddElement: unhandled: <%s>", element->name());
it++;
}
}
}
Expand Down

0 comments on commit 3a8bdf1

Please sign in to comment.