Changing key signature with the Change Instruments function and transposing instruments lead to a crash under certain circumstances

• Mar 11, 2021 - 10:06
Reported version
3.6
Type
Functional
Frequency
Few
Severity
S2 - Critical
Reproducibility
Always
Status
closed
Regression
No
Workaround
No
Project

Version 3.6.2 / Windows 10

First reported here: https://musescore.org/en/node/318636

I don't know what happens internally, the unique trigger (if there is one?), but I can reproduce from scratch. First of all, there are a number of necessary conditions: at least 2 instruments, with parts.

And it doesn't matter if we are in pitch concert or not.

There seems to be a mishmash with Instruments change, transposing instruments, and key signatures, except however from what I can see at the moment, if the instrument that has been changed is not transposing, for example piano or flute.

Steps (example for this test file) : flute and clarinett.mscz

  1. Create a score for 2 flutes, 4 measures
  2. Generate parts
  3. Make an instrument change, from the second flute, to a clarinet.
  4. Select the first measure (first or second flute, no matter)
  5. Click the key signature in A (3 sharps)

Result : crash

  • It fails also with this file (same steps #4 and 5) : 2 clari sax tenor.mscz

  • Works with this one : for step #5, choose key signature eg in D (2 sharps, or other, except so 3 sharps, same as concert pitch) : Clarinett and flute.mscz


Comments

Title Changing key signature with the Change Instruments function and transposing instruments lead ot a crash under certain circumstances Changing key signature with the Change Instruments function and transposing instruments lead to a crash under certain circumstances

Stack trace:
1 Ms::KeySig::showCourtesy keysig.h 66 0x10360dc
2 Ms::Score::updateInstrumentChangeTranspositions edit.cpp 3957 0x9768aa
3 Ms::Score::undoChangeKeySig edit.cpp 3909 0x97630a
4 Ms::Measure::drop measure.cpp 1537 0xa0b1aa
5 Ms::applyDrop palette.cpp 484 0x6c1977
6 Ms::Palette::applyPaletteElement palette.cpp 740 0x6c32f8
7 Ms::UserPaletteController::applyPaletteElement paletteworkspace.cpp 579 0x505ba7
8 Ms::AbstractPaletteController::qt_static_metacall moc_paletteworkspace.cpp 287 0x5f1042
9 Ms::AbstractPaletteController::qt_metacall moc_paletteworkspace.cpp 339 0x5f122e
10 Ms::UserPaletteController::qt_metacall moc_paletteworkspace.cpp 432 0x5f13bf
11 QQmlObjectOrGadget::metacall(QMetaObject::Call, int, void * *) const 0x66255e90
12 CallMethod(QQmlObjectOrGadget const&, int, int, int, int *, QV4::ExecutionEngine *, QV4::CallData *, QMetaObject::Call) 0x661a0674
13 CallPrecise(QQmlObjectOrGadget const&, QQmlPropertyData const&, QV4::ExecutionEngine *, QV4::CallData *, QMetaObject::Call) 0x661a17a4
14 QV4::QObjectMethod::callInternal(QV4::Value const *, QV4::Value const *, int) const 0x661a2564
15 QV4::Moth::VME::interpret(QV4::CppStackFrame *, QV4::ExecutionEngine *, const char *) 0x661b3e78
16 QV4::Moth::VME::exec(QV4::CppStackFrame *, QV4::ExecutionEngine *) 0x661b6dff
17 QV4::Function::call(QV4::Value const *, QV4::Value const *, int, QV4::ExecutionContext const *) 0x66158fae
18 QQmlJavaScriptExpression::evaluate(QV4::CallData *, bool *) 0x6626cc9c
19 QQmlBoundSignalExpression::evaluate(void * *) 0x6622a851
20 QQmlBoundSignal_callback(QQmlNotifierEndpoint *, void * *) 0x6622bd7b
...

Seams an easy fix:

diff --git a/libmscore/edit.cpp b/libmscore/edit.cpp
index d15ce784a..145e05459 100644
--- a/libmscore/edit.cpp
+++ b/libmscore/edit.cpp
@@ -3940,7 +3940,6 @@ void Score::updateInstrumentChangeTranspositions(KeySigEvent& key, Staff* staff,
                         Measure* m = tick2measure(Fraction::fromTicks(nextTick));
                         Segment* s = m->tick2segment(Fraction::fromTicks(nextTick), SegmentType::KeySig);
                         int track = staff->idx() * VOICES;
-                        KeySig* keySig = toKeySig(s->element(track));
                         if (key.isAtonal() && !e.isAtonal()) {
                               e.setMode(KeyMode::NONE);
                               e.setKey(Key::C);
@@ -3954,7 +3953,9 @@ void Score::updateInstrumentChangeTranspositions(KeySigEvent& key, Staff* staff,
                               nkey = transposeKey(nkey, previousTranspose);
                               e.setKey(nkey);
                               }
-                        undo(new ChangeKeySig(keySig, e, keySig->showCourtesy()));
+                        KeySig* keySig = toKeySig(s->element(track));
+                        if (keySig)
+                              undo(new ChangeKeySig(keySig, e, keySig->showCourtesy()));
                         nextTick = kl->nextKeyTick(nextTick);
                         }
                   else