Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix GH#359: Crash on Voice2-4 expanding into new measure #364

Conversation

worldwideweary
Copy link

Resolves: #359
Instead of only reverting the change, I tried to get the same "intention" as the 4.x branch by way of seeing if the resulting "total fraction" was going to spill over into the next measure. If so, then perform the expand function (it was crashing because 3.x apparently needs to expand there when extending past current measure). Putting it back in how it was would cause unnecessary rests though every time. Test please if you're willing...

I have a screen cast showing how it doesn't make a voice-2 rest for no reason and also that it doesn't crash on my side over here if it "spills over".

screencast.mp4

expandVoice(seg, cr1->track());
}
}
}
makeGap(cr1->segment(), cr1->track(), f2, tuplet, first);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good, this is exactly the place it crashes

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any idea why this doesn't seem needed in master?

@Jojo-Schmitz Jojo-Schmitz changed the title Fix #359: Crash on Voice2-4 expanding into new measure Fix GH#359: Crash on Voice2-4 expanding into new measure Mar 4, 2024
@Jojo-Schmitz
Copy link
Owner

Jojo-Schmitz commented Mar 4, 2024

Hmm, this seems to bring back the original issue:
image
select the F, press 6
image

@worldwideweary
Copy link
Author

Hm, okay.. into the next-next measure. Originally it used to happen even without going into the next measure when increasing the duration like this (this is 3.6.2:)

screencast2.mp4

I'll check it out later tomorrow. I think if I were to just reset the boolean i put in there afterwards, it'd be okay but that's just a quick guess.

@worldwideweary worldwideweary force-pushed the 3.7-FixCrashExpandingVoiceIntoNextMeasure branch from dd4feb2 to 00595b7 Compare March 4, 2024 10:14
@worldwideweary
Copy link
Author

I threw in a reset of the expand boolean test. Try it out. For me it's sleep time.

@Jojo-Schmitz
Copy link
Owner

Good night!

@Jojo-Schmitz
Copy link
Owner

Jojo-Schmitz commented Mar 4, 2024

Yep, that fixes it.
I'd prefer though to have thes first 2 lines of your PR nearer to where they are used, i.e. directly before the for-loop, maybe like this:

diff --git a/libmscore/cmd.cpp b/libmscore/cmd.cpp
index 5eb6c9ecff..35eee14b12 100644
--- a/libmscore/cmd.cpp
+++ b/libmscore/cmd.cpp
@@ -1384,8 +1384,17 @@ void Score::changeCRlen(ChordRest* cr, const Fraction& dstF, bool fillWithRest)
       Chord* oc      = 0;

       bool first = true;
+      bool expand = ((cr->tick() + dstF) > Fraction(1, 1));
       for (Fraction f2 : qAsConst(flist)) {
             f  -= f2;
+            if (expand) {
+                  if (auto nm = cr1->measure()->nextMeasure()) {
+                        if (auto seg = nm->first(SegmentType::ChordRest)) {
+                              expandVoice(seg, cr1->track());
+                              }
+                        }
+                  expand = false;
+                  }
             makeGap(cr1->segment(), cr1->track(), f2, tuplet, first);

             if (cr->isRest()) {

The following does not work though:

diff --git a/libmscore/cmd.cpp b/libmscore/cmd.cpp
index 5eb6c9ecff..4cf6313442 100644
--- a/libmscore/cmd.cpp
+++ b/libmscore/cmd.cpp
@@ -1386,6 +1386,14 @@ void Score::changeCRlen(ChordRest* cr, const Fraction& dstF, bool fillWithRest)
       bool first = true;
       for (Fraction f2 : qAsConst(flist)) {
             f  -= f2;
+            bool expand = ((cr1->tick() + f) > Fraction(1, 1));
+            if (expand) {
+                  if (auto nm = cr1->measure()->nextMeasure()) {
+                        if (auto seg = nm->first(SegmentType::ChordRest)) {
+                              expandVoice(seg, cr1->track());
+                              }
+                        }
+                  }
             makeGap(cr1->segment(), cr1->track(), f2, tuplet, first);

             if (cr->isRest()) {

@worldwideweary
Copy link
Author

worldwideweary commented Mar 4, 2024

Checking in:
This PR needed a change of code - was still creating needless rests because of score-wide tick() instead of relative-tick for the exceeding of Frac(1/1) check. Also just verified "first" instead of resetting the boolean.

@worldwideweary worldwideweary force-pushed the 3.7-FixCrashExpandingVoiceIntoNextMeasure branch from 51df4b4 to a726261 Compare March 4, 2024 21:30
@Jojo-Schmitz
Copy link
Owner

Unfortunately this crashes when prolonging a non-voice 1 note across more than 1 measure, like a quarter on beat four (in 4/4 time sig) to a longa (8) or maxima (9)

@worldwideweary
Copy link
Author

Damn.

@Jojo-Schmitz
Copy link
Owner

Jojo-Schmitz commented Mar 5, 2024

Maybe add the check from #359 (comment) ?
It sure does prevent the crash, but also makes it impüossible to prolong across onto a 2,d (or 3rd) measure

@worldwideweary
Copy link
Author

I'll try a few things in a moment shortly

@worldwideweary
Copy link
Author

Looks like the code needs to check for needing expansion on every loop,... which is worse than just verifying an invalid CR...

@worldwideweary worldwideweary force-pushed the 3.7-FixCrashExpandingVoiceIntoNextMeasure branch from a726261 to 0d777fd Compare March 5, 2024 10:14
@worldwideweary
Copy link
Author

worldwideweary commented Mar 5, 2024

Demonstration: it should be okay. Test ? ;)

screencast2.mp4

@@ -1465,7 +1477,8 @@ void Score::changeCRlen(ChordRest* cr, const Fraction& dstF, bool fillWithRest)
if (m1 == 0)
break;
Segment* s = m1->first(SegmentType::ChordRest);
cr1 = toChordRest(s->element(track));
if (!(cr1 = toChordRest(s->element(track))))
break;
Copy link
Owner

@Jojo-Schmitz Jojo-Schmitz Mar 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be worth an assert, like "this shouldn't happen, ever"?

@Jojo-Schmitz
Copy link
Owner

Jojo-Schmitz commented Mar 5, 2024

Looks good. But how about this:

diff --git a/libmscore/cmd.cpp b/libmscore/cmd.cpp
index 5eb6c9ecff..8522c14fa0 100644
--- a/libmscore/cmd.cpp
+++ b/libmscore/cmd.cpp
@@ -1384,8 +1384,17 @@ void Score::changeCRlen(ChordRest* cr, const Fraction& dstF, bool fillWithRest)
       Chord* oc      = 0;

       bool first = true;
+      Fraction totalLen = cr->rtick() + f;
       for (Fraction f2 : qAsConst(flist)) {
             f  -= f2;
+            if (totalLen.reduced() > Fraction(1, 1)) {
+                  if (auto nm = cr1->measure()->nextMeasure()) {
+                        if (auto seg = nm->first(SegmentType::ChordRest)) {
+                              expandVoice(seg, track);
+                              totalLen.setNumerator(totalLen.numerator() - totalLen.denominator());
+                              }
+                        }
+                  }
             makeGap(cr1->segment(), cr1->track(), f2, tuplet, first);

             if (cr->isRest()) {
@@ -1462,10 +1471,12 @@ void Score::changeCRlen(ChordRest* cr, const Fraction& dstF, bool fillWithRest)
                   }
             Measure* m  = cr1->measure();
             Measure* m1 = m->nextMeasure();
-            if (m1 == 0)
+            if (!m1)
                   break;
             Segment* s = m1->first(SegmentType::ChordRest);
             cr1 = toChordRest(s->element(track));
+            if (!cr1)
+                  break;
             }
       connectTies();
       }

(not sure about whether to have an assert at the end, probably not, it seems it will happen)

@worldwideweary
Copy link
Author

worldwideweary commented Mar 5, 2024

I'd leave the assert out, but your changes are fine... it's the same thing. Hell, the compiler will probably optimize the stuff anyways to be the exact same anyways. In other words, "Six one way, half-a-dozen the other".

@worldwideweary worldwideweary force-pushed the 3.7-FixCrashExpandingVoiceIntoNextMeasure branch from 0d777fd to b38a53e Compare March 5, 2024 21:39
@Jojo-Schmitz Jojo-Schmitz merged commit c459891 into Jojo-Schmitz:3.x Mar 5, 2024
@fernandomartin777
Copy link

It's working perfectly now. Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Shortcut to increase note or rest duration beyond the measure causes instant crash
3 participants