Crash on Halftime plugin

• Sep 29, 2015 - 20:12
Type
Functional
Severity
S2 - Critical
Status
closed

MuseScore 2.0.2 / Windows7

1) "My First Score"

2) Input some notes

3) Plugins -> Press 'Halftime'

Halftime.jpg

Result: crash


Comments

The problem comes from full measure rests.
Here is a backtrace:
655 Q_ASSERT(_sd.numerator());
#0 Ms::Score::makeGap (this=0x20c3f618, segment=0x21248188, track=0, _sd=..., tuplet=0x0, keepChord=false)
at C:\Git_packages\MuseScore\libmscore\cmd.cpp:655
#1 0x0079f12d in Ms::Score::setNoteRest (this=0x20c3f618, segment=0x21248188, track=0, nval=..., sd=..., stemDirection=Ms::MScore::Direction::AUTO)
at C:\Git_packages\MuseScore\libmscore\cmd.cpp:529
#2 0x007b00ec in Ms::Score::addPitch (this=0x20c3f618, nval=..., addFlag=false)
at C:\Git_packages\MuseScore\libmscore\edit.cpp:1139
#3 0x00915ed3 in Ms::Cursor::addNote (this=0x2103abe0, pitch=60)
at C:\Git_packages\MuseScore\libmscore\cursor.cpp:161
#4 0x00865a68 in Ms::Cursor::qt_static_metacall (_o=0x2103abe0, _c=QMetaObject::InvokeMetaMethod, _id=4, _a=0x28bbf0)
at C:/Git_packages/MuseScore/build.debug/libmscore/moc_cursor.cpp:126
#5 0x00865b89 in Ms::Cursor::qt_metacall (this=0x2103abe0, _c=QMetaObject::InvokeMetaMethod, _id=4, _a=0x28bbf0)
at C:/Git_packages/MuseScore/build.debug/libmscore/moc_cursor.cpp:159

When the plugin hits a measure rest, the chord.durationType is 0, therefore the calculated new duration (inside the plugin at line 66 var dur = chord.durationType/15;) is 0 as well and this triggers the assert check since the numerator is 0 (fraction is 0/1).
If the measure rests in "My_First_Score" are substituted by whole (4/4) rests the crash disappears.

I changed the "project" field since the bug lies in how the plugin handles the halving of measure rests rather than how notes/rests are inserted in MuseScore.

Status (old) active patch (code needs review)

As much as I figured it out, the reason for segfault in this case is that full measure rests are saved as rests with duration 0. That is why assertion on top of Score::makeGap() raises segmentation fault when you try to create one (0/2 = 0). For now, you can use modified version of plug-in (attached), but adding safeguard somewhere around Score::makeGap() or Score::setNoteRest() would probably be a good idea (suggestion to core developers).

Attachment Size
halftime.qml 4.87 KB

Thanks for reviewing this issue.
The initial crash is fixed. I note, however, other "bad things" that lead easily to another crash and corruption (I say this for information, because I don't know which degree of stability is believed to have a plugin?)
I suppose however this kind of issues on "basic" operations should be avoided, at least.

Steps for reproduce:

1) "My First Score"
2) Input four quarter notes in the first measure
3) Plugins -> Halftime
4) Select these notes (image below) -> Hit "R" key (or copy-paste onto the half rest of the same first measure)
selection.jpg
Result: crash

Notes:
- If you copy-paste these notes onto other empty easures in the score, the whole rests are deleted (ie corruption)
- Same origine I guess: Note input mode: select the half note value and input a note on the half rest, always first measure. Result: failure, and corruption.

Status (old) active patch (code needs review)

Here are updated versions of both the halftime and the doubletime plugins where both the durationtype and the actual duration are set correctly.
The bug in #5 was coming from the fact that the duration was not set and therefore the chords and rests had a duration of 0/1 (this could be seen in the debugger in a Nightly build, for example).

I couldn't find a way to add a rest at a cursor position with a simple instruction such as "addRest" or similar, therefore I used a workaround.

I also found that when adding a chord or a rest via a plugin, the underlying chords/rests are not deleted. This can originate a corrupted state. I will report this in a different bug report.

Possible future refinement of these plugin could be the use of halved/doubled time signatures instead of 4/4 (I used 8/4 in the doubletime).

Attachment Size
halftime_v2_0_1.qml 4.92 KB
doubletime_v2_0_1.qml 5.06 KB

Hi!
I use scores for bells with not standart nuber of lines. See mscz file attached.
Both Halftime and Doubletime v.2.0.1 works when I use first and second staves but
1. crash when I try to use third stave (bells 3);
2. don't process double notes (see "bells 1");
3. add an extra note at the end;
4. do not save clefs and number of lines of stave.
(see plug_test.jpg)

Attachment Size
plug_test.mscz 4.71 KB
plug_test.jpg 127.9 KB

Not yet, my cmake is currently going awol and stopped making c++0x instructions. I can verify half/doubletime once I've got that sorted (unless *someone* beats me to it)

One of the problem is that I was wrongly assuming the behavior of cursor.addNote.
Here are the versions which work up to two staves, without using the original instruments and key/time signatures. For those advanced cases probably the available plugin functions should be increased.
Sorry for not having posted this solution before: I had it since the beginning of January and I wanted to work on the number of instruments/tracks, but then I never found the time to complete it. This is just the "limited" version of the plugins.

For updating the segment I was using the trick which was already in use: rewind and then advance the cursor by the number of chords already written.

Attachment Size
doubletime_v2_0_2.qml 5.94 KB
halftime_v2_0_2.qml 5.79 KB

Thanks a lot for this new version, but it still crashes for me. Hopefully the attached debug will shed some light.

As mentioned elsewhere, whilst I'm clueless about MuseScore internals and plugins, I'm a software developer (have previously contributed to LilyPond) and am very keen to help fix things if given a few pointers on basic MuseScore debugging techniques.

Attachment Size
doubletime-v2.0.2.segfault.txt 14.44 KB

The place to start to learn about development for MuseScore is the Development link in the menu at right of this page. See especially the Deverlopers Handbook, which contains lots of useful information on compiling, debugging, the data structures, etc.

This worked without crashing v 2.0.3.

Limitation
Great for single line part/s or when all the part/s are in the same voice.
I had difficulties when using a grand staff (piano) with several voices used for each hand. It would drop everything in the bass clef (left hand) and leave out anything in the second voice/part in either hand.

Doubletime v 2_0_2 works with one stave at a time in MuseScore 2.0.3, still it does a good work and saves a lot of headaches.
Halftime v 2_0_2 works fine with two staves at a time in MuseScore 2.0.3.

In reply to by adam.spiers

I don't know what to do with this patch. I open the file and all I see is a bunch of code. Is it intended to fix the problem of Doubletime causing Musescore to crash (which has happened to me)?

I am not an 'advanced user'. Please make it simple and, if necessary, step by step.
Thank you.
Sincerely,
Keith Lawrence

In reply to by Jojo-Schmitz

Title Crash on Halftime plugin Crash on Doubletime plug-in
Severity S2 - Critical S5 - Suggestion
Status (old) patch (code needs review) won't fix
Status won't fix
Reported version 2.1

I took the file you cited (the alleged correction of Doubletime), saved it 'as' Doubletime. Same result, even worse. Entire system crashed, not only Musescore. Afterwards, Musescore was very slow in opening. Had to double-click on the icon several times.

Can we go back to square minus 1??

Assume I am a rank beginner (pretty close to the truth). Exactly what do I have to do to get Doubletime to work? Once the patch is installed does it have instructions on how to use it??
Thank you for your help.
Sincerely,]
Keith Lawrence

Title Crash on Doubletime plug-in Crash on Halftime plugin
Severity S5 - Suggestion S2 - Critical
Status (old) won't fix patch (code needs review)
Status won't fix  
Reported version 2.1