Ambitus crash in plugins

• Jul 22, 2019 - 09:08
Reported version
3.2
Type
Plugins
Frequency
Many
Severity
S4 - Minor
Reproducibility
Always
Status
PR created
Regression
No
Workaround
No
Project

It's tedious to have to add an ambitus to every part of a 16-part piece (and when did anyone want an ambitus on only one part?) so I tried to write a plugin to do it. However all I achieved was to crash Musescore:
var cursor = curScore.newCursor();
cursor.voice = 0;
cursor.staffIdx = 0;
cursor.rewind(Cursor.SCORE_START);
cursor.next(); //still crashes without this line
var el=newElement(Element.AMBITUS);
cursor.add(el); //always crashes

I looked to see if I could locate the Clef element as the ambitus is normally dropped on the clef but the cursor always seems to point to chord segments, never a clef or time change.

David


Comments

Frequency Many Once
Workaround No Yes

Outside of a plugin it is possible to add several ambitus at once. Click a clef, ctrl+click additional clefs the double click the ambitus in the palette to apply one to all of those staves at once.

BTW, frequency is how many times it's been reported - you're #1.

Frequency Once Many
Workaround Yes No

Confirmed.

It's crashing after, where in a debug build, you would get an assertion failure:

void Segment::add(Element* el)
:
case ElementType::AMBITUS:
// FAILS Q_ASSERT Test. _segmentType is ChordRest! It wants SegmentType::Ambitus.
Q_ASSERT(_segmentType == SegmentType::Ambitus);
checkElement(el, track);
_elist[track] = el;
setEmpty(false);
break;

See the code comment above. The code says it can only add an ElementType::AMBITUS element to an SegmentType::Ambitus segment. How to get such a thing I don't know. But this is what happening.

It's bad news that scripted code can crash the application.

Title Ambitus crash Ambitus in bulk

Thank you, Mike - I don't need to write the plugin now! I would never have thought of selecting all the clefs and double-clicking the ambitus, but it certainly works. Perhaps this tip could find its way into the help, or did I miss it?

Title Ambitus in bulk Ambitus crash in plugins

This is a bug that should be addressed. And the actual problem is related to ambitus being added in a plugin leads to a crash.

It is implied, though not explicitly stated that you can select multiple clefs and add an ambitus to each because of the way they are added. I'll think of a way to make this clearer in the handbook.