Skip to content

Commit

Permalink
Merge pull request musescore#18478 from cbjeukendrup/crash_linked_tab
Browse files Browse the repository at this point in the history
Fix crash when creating linked staff for TAB-only staff
  • Loading branch information
RomanPudashkin committed Jul 8, 2023
2 parents bba0d07 + 3af05bc commit e44addf
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions src/engraving/libmscore/staff.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -963,22 +963,31 @@ bool Staff::isPrimaryStaff() const
if (!_links) {
return true;
}
std::vector<Staff*> s;
std::vector<Staff*> ss;
for (auto e : *_links) {
Staff* staff = toStaff(e);

std::vector<const Staff*> linkedStavesInThisScore;
std::vector<const Staff*> linkedNonTabStavesInThisScore;

for (const EngravingObject* linked : *_links) {
const Staff* staff = toStaff(linked);

if (staff->score() == score()) {
s.push_back(staff);
linkedStavesInThisScore.push_back(staff);

if (!staff->isTabStaff(Fraction(0, 1))) {
ss.push_back(staff);
linkedNonTabStavesInThisScore.push_back(staff);
}
}
}
if (s.size() == 1) { // the linked staves are in different scores
return s.front() == this;
} else { // return a non tab linked staff in this score
return ss.front() == this;

IF_ASSERT_FAILED(!linkedStavesInThisScore.empty()) {
return true;
}

if (!linkedNonTabStavesInThisScore.empty()) {
return linkedNonTabStavesInThisScore.front() == this;
}

return linkedStavesInThisScore.front() == this;
}

//---------------------------------------------------------
Expand Down

0 comments on commit e44addf

Please sign in to comment.