Skip to content

Commit

Permalink
Merge pull request #25686 from mathesoncalum/25676-paste_dynamic_crash
Browse files Browse the repository at this point in the history
Fix #25676: When pasting a dynamic, `undoAdd` a segment if it doesn't already exist
  • Loading branch information
RomanPudashkin authored Dec 2, 2024
2 parents e30f030 + cac2cd6 commit 3c552c7
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
17 changes: 17 additions & 0 deletions src/engraving/dom/measure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -722,6 +722,23 @@ Segment* Measure::getChordRestOrTimeTickSegment(const Fraction& f)
return seg;
}

Segment* Measure::undoGetChordRestOrTimeTickSegment(const Fraction& f)
{
Segment* seg = findSegment(SegmentType::ChordRest, f);
if (!seg) {
seg = findSegment(SegmentType::TimeTick, f);
}
if (!seg) {
if (f - tick() == ticks()) { // end of measure
seg = undoGetSegment(SegmentType::TimeTick, f);
} else {
seg = undoGetSegment(SegmentType::ChordRest, f);
}
}

return seg;
}

//---------------------------------------------------------
// getSegmentR
/// Get a segment of type st at relative tick position t.
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 @@ -260,6 +260,7 @@ class Measure final : public MeasureBase
Segment* findSegment(SegmentType st, const Fraction& f) const { return findSegmentR(st, f - tick()); }
Segment* undoGetSegment(SegmentType st, const Fraction& f) { return undoGetSegmentR(st, f - tick()); }
Segment* getSegment(SegmentType st, const Fraction& f) { return getSegmentR(st, f - tick()); }
Segment* undoGetChordRestOrTimeTickSegment(const Fraction& f);
Segment* getChordRestOrTimeTickSegment(const Fraction& f);

void connectTremolo();
Expand Down
2 changes: 1 addition & 1 deletion src/engraving/rw/read410/read410.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,7 @@ bool Read410::pasteStaff(XmlReader& e, Segment* dst, staff_idx_t dstStaff, Fract

Fraction tick = doScale ? (ctx.tick() - dstTick) * scale + dstTick : ctx.tick();
Measure* m = score->tick2measure(tick);
Segment* seg = m->getChordRestOrTimeTickSegment(tick);
Segment* seg = m->undoGetChordRestOrTimeTickSegment(tick);
el->setParent(seg);

// be sure to paste the element in the destination track;
Expand Down

0 comments on commit 3c552c7

Please sign in to comment.