fix #163691: crash on undo with links to self #3159
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When we remove a linked staff, the elements on the remaining staff still contain links to the corresponding elements on the removed staff. This is something that has bothered me for some time, and I'm pretty sure it leads to other problems as well. So ultimately, I still think we should address this.
However, that would undoubtedly have major ramifications, so I am not going there right now. The issue at hand - https://musescore.org/en/node/163691 - is triggered by the specific case of an element linked to itself that results from removal of a linked staff followed by save/reload. If you then remove the remaining staff and undo, you get an assertion failure. I elected to go with a "100% safe" solution. I simply removed the assert statement that led to the crash, and just return without doing anything in that case. No crash, and it has the added benefit of fixing the link to self thus hopefully reducing the likelihood of further problems.
Worst case, some series of steps that formerly crashed right away due the assertion failure will now crash later.