Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #25145: Crash relating to StaffTypeChange #26289

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/engraving/dom/measure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1395,6 +1395,9 @@ bool Measure::acceptDrop(EditData& data) const
viewer->setDropRectangle(canvasBoundingRect());
return true;
case ActionIconType::STAFF_TYPE_CHANGE:
if (!canAddStaffTypeChange(staffIdx)) {
return false;
}
viewer->setDropRectangle(staffRect);
return true;
case ActionIconType::SYSTEM_LOCK:
Expand Down Expand Up @@ -1736,6 +1739,9 @@ EngravingItem* Measure::drop(EditData& data)
score()->insertMeasure(ElementType::MEASURE, this);
break;
case ActionIconType::STAFF_TYPE_CHANGE: {
if (!canAddStaffTypeChange(staffIdx)) {
return nullptr;
}
EngravingItem* stc = Factory::createStaffTypeChange(this);
stc->setParent(this);
stc->setTrack(staffIdx * VOICES);
Expand Down Expand Up @@ -3475,6 +3481,21 @@ bool Measure::canAddStringTunings(staff_idx_t staffIdx) const
return !alreadyHasStringTunings;
}

bool Measure::canAddStaffTypeChange(staff_idx_t staffIdx) const
{
for (const EngravingObject* child : el()) {
if (!child || !child->isStaffTypeChange()) {
continue;
}
const StaffTypeChange* stc = toStaffTypeChange(child);
if (stc->staffIdx() == staffIdx) {
// Staff already has a StaffTypeChange at this measure...
return false;
}
}
return true;
}

Fraction Measure::maxTicks() const
{
Segment* s = first();
Expand Down
1 change: 1 addition & 0 deletions src/engraving/dom/measure.h
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,7 @@ class Measure final : public MeasureBase
void respaceSegments();

bool canAddStringTunings(staff_idx_t staffIdx) const;
bool canAddStaffTypeChange(staff_idx_t staffIdx) const;

private:

Expand Down
7 changes: 6 additions & 1 deletion src/engraving/rw/read400/tread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3638,7 +3638,12 @@ void TRead::read(Spacer* s, XmlReader& e, ReadContext& ctx)

void TRead::read(StaffType* t, XmlReader& e, ReadContext&)
{
t->setGroup(TConv::fromXml(e.asciiAttribute("group"), StaffGroup::STANDARD));
const AsciiStringView group = e.asciiAttribute("group");
IF_ASSERT_FAILED(!group.empty()) {
return;
}

t->setGroup(TConv::fromXml(group, StaffGroup::STANDARD));

if (t->group() == StaffGroup::TAB) {
t->setGenKeysig(false);
Expand Down
7 changes: 6 additions & 1 deletion src/engraving/rw/read410/tread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4107,7 +4107,12 @@ void TRead::read(Spacer* s, XmlReader& e, ReadContext& ctx)

void TRead::read(StaffType* t, XmlReader& e, ReadContext&)
{
t->setGroup(TConv::fromXml(e.asciiAttribute("group"), StaffGroup::STANDARD));
const AsciiStringView group = e.asciiAttribute("group");
IF_ASSERT_FAILED(!group.empty()) {
return;
}

t->setGroup(TConv::fromXml(group, StaffGroup::STANDARD));

if (t->group() == StaffGroup::TAB) {
t->setGenKeysig(false);
Expand Down
8 changes: 6 additions & 2 deletions src/notation/internal/notationinteraction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2516,9 +2516,13 @@ bool NotationInteraction::dragMeasureAnchorElement(const PointF& pos)
RectF measureRect = targetMeasure->staffPageBoundingRect(staffIdx);
measureRect.adjust(page->x(), page->y(), page->x(), page->y());
m_dropData.ed.pos = measureRect.center();
setAnchorLines({ LineF(pos, measureRect.topLeft()) });

return targetMeasure->acceptDrop(m_dropData.ed);
const bool dropAccepted = targetMeasure->acceptDrop(m_dropData.ed);
if (dropAccepted) {
setAnchorLines({ LineF(pos, measureRect.topLeft()) });
}

return dropAccepted;
}
dropElem->score()->addRefresh(dropElem->canvasBoundingRect());
setDropTarget(nullptr);
Expand Down