Skip to content

Commit

Permalink
Ensure we always select MMRest measures, not underlying ones
Browse files Browse the repository at this point in the history
Because underlying ones are possibly not considered during layout, and thus may not have a `system()` which can cause crashes.

(all of this only applies when MMRests are actually enabled, but that is checked for by `coveringMMRestOrThis`.)

Resolves: #23878
  • Loading branch information
cbjeukendrup committed Mar 9, 2025
1 parent f32615b commit c85832e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
7 changes: 6 additions & 1 deletion src/engraving/dom/measure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2898,7 +2898,7 @@ Measure* Measure::mmRestLast() const
// otherwise, return the measure itself.
//---------------------------------------------------------

const Measure* Measure::coveringMMRestOrThis() const
Measure* Measure::coveringMMRestOrThis()
{
if (!style().styleB(Sid::createMultiMeasureRests)) {
return this;
Expand All @@ -2924,6 +2924,11 @@ const Measure* Measure::coveringMMRestOrThis() const
return 0;
}

const Measure* Measure::coveringMMRestOrThis() const
{
return const_cast<Measure*>(this)->coveringMMRestOrThis();
}

int Measure::measureRepeatCount(staff_idx_t staffIdx) const
{
if (staffIdx >= m_mstaves.size()) {
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 @@ -303,6 +303,7 @@ class Measure final : public MeasureBase
bool hasMMRest() const { return m_mmRest != 0; }
bool isMMRest() const { return m_mmRestCount > 0; }
Measure* mmRest() const { return m_mmRest; }
Measure* coveringMMRestOrThis();
const Measure* coveringMMRestOrThis() const;
void setMMRest(Measure* m) { m_mmRest = m; }
int mmRestCount() const { return m_mmRestCount; } // number of measures m_mmRest spans
Expand Down
14 changes: 7 additions & 7 deletions src/engraving/dom/score.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3492,7 +3492,7 @@ void Score::selectSingle(EngravingItem* e, staff_idx_t staffIdx)
setUpdateAll();
} else {
if (e->isMeasure()) {
doSelect(e, SelectType::RANGE, staffIdx);
doSelect(toMeasure(e)->coveringMMRestOrThis(), SelectType::RANGE, staffIdx);
return;
}
addRefresh(e->pageBoundingRect());
Expand Down Expand Up @@ -3539,11 +3539,11 @@ void Score::selectAdd(EngravingItem* e)
}

if (e->isMeasure()) {
Measure* m = toMeasure(e);
Measure* m = toMeasure(e)->coveringMMRestOrThis();
Fraction tick = m->tick();
if (m_selection.isNone()) {
m_selection.setRange(m->tick2segment(tick),
m == lastMeasure() ? 0 : m->last(),
m == lastMeasureMM() ? 0 : m->last(),
0,
nstaves());
setUpdateAll();
Expand Down Expand Up @@ -3637,9 +3637,9 @@ void Score::selectRange(EngravingItem* e, staff_idx_t staffIdx)
}

if (e->isMeasure()) {
Measure* m = toMeasure(e);
Measure* m = toMeasure(e)->coveringMMRestOrThis();
Segment* startSegment = m->first(SegmentType::ChordRest);
Segment* endSegment = m == lastMeasure() ? nullptr : m->last();
Segment* endSegment = m == lastMeasureMM() ? nullptr : m->last();
Fraction tick = m->tick();
Fraction etick = tick + m->ticks();

Expand Down Expand Up @@ -3773,14 +3773,14 @@ bool Score::tryExtendSingleSelectionToRange(EngravingItem* newElement, staff_idx
bool activeSegmentIsStart = false;

if (newElement->isMeasure()) {
Measure* m = toMeasure(newElement);
Measure* m = toMeasure(newElement)->coveringMMRestOrThis();
const Fraction tick = m->tick();

if (tick < startSegment->tick()) {
startSegment = m->first(SegmentType::ChordRest);
activeSegmentIsStart = true;
}
if (m == lastMeasure()) {
if (m == lastMeasureMM()) {
endSegment = nullptr;
} else if (endSegment && tick + m->ticks() > endSegment->tick()) {
endSegment = m->last();
Expand Down

0 comments on commit c85832e

Please sign in to comment.