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 #290929: crash with negative number of dots for rests #5226

Closed
wants to merge 1 commit into from

Conversation

Jojo-Schmitz
Copy link
Contributor

@Jojo-Schmitz Jojo-Schmitz commented Jul 16, 2019

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.

@Jojo-Schmitz Jojo-Schmitz changed the title Fix/avoid a crash with dotted rests @Jojo-Schmitz Fix #290929: crash with negative number of dots for rests Jul 16, 2019
@Jojo-Schmitz Jojo-Schmitz changed the title @Jojo-Schmitz Fix #290929: crash with negative number of dots for rests Fix #290929: crash with negative number of dots for rests Jul 16, 2019
@@ -429,7 +429,7 @@ void Rest::checkDots()
dot->setVisible(visible());
score()->undoAddElement(dot);
}
if (n < 0) {
if (n < 0 && _dots.size()) {
Copy link
Contributor

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.

Copy link
Contributor Author

@Jojo-Schmitz Jojo-Schmitz Jul 19, 2019

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.

Copy link
Contributor Author

@Jojo-Schmitz Jojo-Schmitz Jul 19, 2019

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());
              }
        }

Copy link
Contributor

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.

Copy link
Contributor Author

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?

Copy link
Contributor

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.

@anatoly-os
Copy link
Contributor

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.

@dmitrio95
Copy link
Contributor

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.

@anatoly-os
Copy link
Contributor

The test won't be useless anyway. I agree, I didn't get why we need this PR. @Jojo-Schmitz ?)

@dmitrio95
Copy link
Contributor

I agree, I didn't get why we need this PR

This one was created earlier :)

@Jojo-Schmitz
Copy link
Contributor Author

This PR is not needed anymore, it was meant as an alternative to the other.
We never found how those broken scores bacem that broken, so a test file would be completly artificial and may not test the real sitiation.
I'd rather just close this...

@Jojo-Schmitz Jojo-Schmitz deleted the rest-dot-crash branch July 26, 2019 14:04
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.

None yet

3 participants