Skip to content

Commit b63a2f4

Browse files
committed
Prevent crash on splitting the shortest possible measure
Backport of musescore#8894, part 2
1 parent 6337823 commit b63a2f4

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed

libmscore/mscore.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ std::vector<MScoreError> MScore::errorList {
143143
{ CANNOT_SPLIT_TUPLET, "t2", QT_TRANSLATE_NOOP("error", "Cannot split tuplet") },
144144
{ CANNOT_SPLIT_MEASURE_FIRST_BEAT, "m1", QT_TRANSLATE_NOOP("error", "Cannot split measure here:\n" "First beat of measure") },
145145
{ CANNOT_SPLIT_MEASURE_TUPLET, "m2", QT_TRANSLATE_NOOP("error", "Cannot split measure here:\n" "Cannot split tuplet") },
146+
{ CANNOT_SPLIT_MEASURE_TOO_SHORT, "m3", QT_TRANSLATE_NOOP("error", "Cannot split measure here:\n" "Measure would be too short") },
146147

147148
{ NO_DEST, "p1", QT_TRANSLATE_NOOP("error", "No destination to paste") },
148149
{ DEST_TUPLET, "p2", QT_TRANSLATE_NOOP("error", "Cannot paste into tuplet") },

libmscore/mscore.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@ enum MsError {
248248
CANNOT_SPLIT_TUPLET,
249249
CANNOT_SPLIT_MEASURE_FIRST_BEAT,
250250
CANNOT_SPLIT_MEASURE_TUPLET,
251+
CANNOT_SPLIT_MEASURE_TOO_SHORT,
251252
NO_DEST,
252253
DEST_TUPLET,
253254
TUPLET_CROSSES_BAR,

libmscore/splitMeasure.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ void Score::cmdSplitMeasure(ChordRest* cr)
3636

3737
//---------------------------------------------------------
3838
// splitMeasure
39-
// return true on success
4039
//---------------------------------------------------------
4140

4241
void Score::splitMeasure(Segment* segment)
@@ -111,7 +110,7 @@ void Score::splitMeasure(Segment* segment)
111110
if (ticks1.denominator() < measure->ticks().denominator()) {
112111
if (measure->ticks().denominator() % m1->timesig().denominator() == 0) {
113112
int mult = measure->ticks().denominator() / ticks1.denominator();
114-
// *= operator audomatically reduces via GCD, so rather do literal multiplication:
113+
// *= operator automatically reduces via GCD, so rather do literal multiplication:
115114
ticks1.setDenominator(ticks1.denominator() * mult);
116115
ticks1.setNumerator(ticks1.numerator() * mult);
117116
}
@@ -123,6 +122,10 @@ void Score::splitMeasure(Segment* segment)
123122
ticks2.setNumerator(ticks2.numerator() * mult);
124123
}
125124
}
125+
if (ticks1.denominator() > 128 || ticks2.denominator() > 128) {
126+
MScore::setError(CANNOT_SPLIT_MEASURE_TOO_SHORT);
127+
return;
128+
}
126129
m1->adjustToLen(ticks1, false);
127130
m2->adjustToLen(ticks2, false);
128131
range.write(this, m1->tick());

0 commit comments

Comments
 (0)