-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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 #290929: crash with negative number of dots for rests #5226
Conversation
0bf2430
to
59aeabf
Compare
59aeabf
to
7c7d360
Compare
libmscore/rest.cpp
Outdated
@@ -429,7 +429,7 @@ void Rest::checkDots() | |||
dot->setVisible(visible()); | |||
score()->undoAddElement(dot); | |||
} | |||
if (n < 0) { | |||
if (n < 0 && _dots.size()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That wouldn't probably help if -n > _dots.size()
and _dots
is not empty. It looks like this check should be moved into the loop instead.
Also some qDebug()
or qWarning()
message for this case could perhaps be useful, this situation shouldn't normally happen.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the other fix (option 2) better anyhow, more fixing it at the deepest root, fixes it at read and write too and for rests and chords.
This one here is more curing the symptom, preventing that particular crash.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean something like this?
if (n < 0) {
for (int i = 0; i < -n; ++i) {
if (!_dots.size() || -n > _dots.size()) {
qWarning("no dots at all or number mismatch");
return;
}
score()->undoRemoveElement(_dots.back());
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something like this actually:
if (n < 0) {
for (int i = 0; i < -n; ++i) {
if (_dots.empty()) {
qWarning("no dots at all or number mismatch");
return;
}
score()->undoRemoveElement(_dots.back());
}
}
This will clear dots if -n > _dots.size()
which seems sensible to do in this case.
But maybe the fix in #5235 should indeed be enough so let's apply that one first.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't quite see the difference to my initial change though, except that now we go into the for loop once in the error case, something that the initial fix did not. To me this is just a more expensive way of doing the same thing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no difference if there is no dots initially. If there are some dots but -n
appears to have a large value then the approach I propose will just clear all the dots without crashing the program. But I am not sure whether such situations actually happen.
7c7d360
to
11ca698
Compare
11ca698
to
d88383e
Compare
Could you add the test which opens the file from the bug report? Successful reading the file without a crash will verify the fix and keep the scenario working for the future changes. |
As far as I understand this pull request might be not needed at all since the other fix for the issue, #5235, has already been merged. |
The test won't be useless anyway. I agree, I didn't get why we need this PR. @Jojo-Schmitz ?) |
This one was created earlier :) |
This PR is not needed anymore, it was meant as an alternative to the other. |
See also PR #5235, use either that (done) or this (no longer) or both (still possible).
This here avoids the crash in this particular case, and in that only.