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

[MU4] Fix #330595: Crash on selecting entire score after XML import #10860

Merged
merged 1 commit into from
May 10, 2023

Conversation

Jojo-Schmitz
Copy link
Contributor

@Jojo-Schmitz Jojo-Schmitz commented Mar 22, 2022

Resolves: https://musescore.org/en/node/330595 (the 2nd part, the first part is not an issue with master, looking at its fix for 3.x seems to indicate that this is because #8530 hasn't been ported to master yet? For 3.x and master that crash had been fixed in #8199 resp. #8200, we'd need to make sure it doesn't break again when porting those backend fixes to master)
Applies to 3.x too.
Strange enough: There is no crash when saving the imported XML as an MSCZ, closing and reopening it and doing that "select all" then.

@@ -527,7 +527,7 @@ void Selection::appendChord(Chord* chord)
if (sp->endElement()->isNote()) {
Note* endNote = toNote(sp->endElement());
Segment* s = endNote->chord()->segment();
if (s->tick() < tickEnd()) {
if (s && s->tick() < tickEnd()) {
Copy link
Contributor Author

@Jojo-Schmitz Jojo-Schmitz Mar 22, 2022

Choose a reason for hiding this comment

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

This particular crash happens here, dereferencng s when that is a nullptr

Alternative fix: if (!s || s->tick() < tickEnd()) {, avoids the crash too, but doesn't skip the _el.append(sp). Which would be more correct?

Copy link
Contributor

Choose a reason for hiding this comment

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

I'd be more worried why a chord would ever not have a segment?

Copy link
Contributor Author

@Jojo-Schmitz Jojo-Schmitz Mar 23, 2022

Choose a reason for hiding this comment

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

Well, then check the sample score from that forum post.

Yes, this is curing the symptom rather than the cause. But that isn't a bad thing, or is it?
Just check your pointers before using them.

It is only happening directly after the XML import, not anymore once the score has been saved as mscz (and a close/reopen).

Copy link
Contributor

@wizofaus wizofaus Mar 23, 2022

Choose a reason for hiding this comment

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

Well the issue is as you noted it's not clear what the right behaviour is in this case if a chord doesn't have a segment, and it seems like the sort of thing that might have consequences elsewhere. I'd be trying to fix it in the XML importer first, that's all.
I'd also note that the MS codebase, and even the short sample above, would probably be twice as big if it had to check every pointer first, due to the lack of a null propagation operator in C++.

Copy link
Contributor Author

@Jojo-Schmitz Jojo-Schmitz Mar 24, 2022

Choose a reason for hiding this comment

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

Don't check for error conditions you can't handle... but do check those you can.

I've now tried both methods on the xml from the forum post: the resulting scores are 100% identical.

But yes, of course it'd be better to fix the XML import, I just don't know where to look. @lvinken ?

Copy link
Contributor

Choose a reason for hiding this comment

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

Indeed, MusicXML import should not result in invalid data. Will try to find the root cause.

Copy link
Contributor

Choose a reason for hiding this comment

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

See comment added to https://musescore.org/en/node/330595 for possible root cause, shouldn't be too hard to track down and fix in a structural way.

@@ -518,7 +518,7 @@ void Selection::appendChord(Chord* chord)
if (note->tieFor()->endElement()->isNote()) {
Note* endNote = toNote(note->tieFor()->endElement());
Segment* s = endNote->chord()->segment();
if (s->tick() < tickEnd()) {
if (s && s->tick() < tickEnd()) {
Copy link
Contributor Author

@Jojo-Schmitz Jojo-Schmitz Mar 22, 2022

Choose a reason for hiding this comment

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

This change is just for extra safety, and in analogy to the other (and so the same question applies).

Jojo-Schmitz added a commit to Jojo-Schmitz/MuseScore that referenced this pull request Mar 22, 2022
Backport of musescore#10860, plus a fix on importing an empty XML file,
which doesn't apply to master
Jojo-Schmitz added a commit to Jojo-Schmitz/MuseScore that referenced this pull request Mar 23, 2022
Backport of musescore#10860, plus a fix on importing an empty XML file, which
apparently doesn't apply to master. For master it got fix in musescore#8200,
in 3.x it got fixed in musescore#8199, but broke again with the port of musescore#8530.
Jojo-Schmitz added a commit to Jojo-Schmitz/MuseScore that referenced this pull request Mar 23, 2022
Backport of musescore#10860, plus a fix on importing an empty XML file, which
apparently doesn't apply to master. For master it got fix in musescore#8200,
in 3.x it got fixed in musescore#8199, but broke again with the port of musescore#8530.
Converting some `foreach(..., ...)` into `for (... : ...)` along the way.
Jojo-Schmitz added a commit to Jojo-Schmitz/MuseScore that referenced this pull request Mar 24, 2022
Backport of musescore#10860, plus a fix on importing an empty XML file, which
apparently doesn't apply to master. For master it got fix in musescore#8200,
in 3.x it got fixed in musescore#8199, but broke again with the port of musescore#8530.
Converting some `foreach(..., ...)` into `for (... : ...)` along the way.
@Jojo-Schmitz Jojo-Schmitz force-pushed the crash-select-all branch 3 times, most recently from 0471cd6 to d65606e Compare April 16, 2022 11:57
Jojo-Schmitz added a commit to Jojo-Schmitz/MuseScore that referenced this pull request May 12, 2022
Backport of musescore#10860, plus a fix on importing an empty XML file, which
apparently doesn't apply to master. For master it got fix in musescore#8200,
in 3.x it got fixed in musescore#8199, but broke again with the port of musescore#8530.
Converting some `foreach(..., ...)` into `for (... : ...)` along the way.
@Jojo-Schmitz Jojo-Schmitz mentioned this pull request Jan 9, 2023
Jojo-Schmitz added a commit to Jojo-Schmitz/MuseScore that referenced this pull request Mar 5, 2023
Backport of musescore#10860, plus a fix on importing an empty XML file, which
apparently doesn't apply to master. For master it got fix in musescore#8200,
in 3.x it got fixed in musescore#8199, but broke again with the port of musescore#8530.
Converting some `foreach(..., ...)` into `for (... : ...)` along the way.
@Jojo-Schmitz
Copy link
Contributor Author

Jojo-Schmitz commented Mar 14, 2023

This one too is waiting to get reviewed and merged since almost a year now.

@RomanPudashkin RomanPudashkin merged commit 0862e06 into musescore:master May 10, 2023
@Jojo-Schmitz Jojo-Schmitz deleted the crash-select-all branch May 10, 2023 12:21
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.

4 participants