Spinell/maya 110157/clearing mutiple layer crash #1274
Merged
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 clearing multiple layer at the same time, maya crash because of a dangling pointer. This happen when in the selected layers, there is a sub layer of another layer. When clearing layers, we are first getting a list of all selected layers than loop over the list and clear layer one by one (Same pattern as remove layer). The problem here is after the first clear, we are notified by USD that a layer changed and we are queuing a Layer Editor refresh on idle. On the next loop iteration, items can become a dangling pointer to an object that have been deleted if the Layer Editor refresh already happen (During the refresh all the items are deleted are recreated).
Let suppose you have the fallowing hierarchy:
layer1
layer2
layer3
layer4
If all layers are selected and layer1 is cleared first, sub layer2 is removed from layer1 and a Layer Editor refresh callback is set on idle. If the refresh happen before we finish to iterate on the selected items, the selection list will contains dangling pointer.
To be sure the Layer Editor is not refreshing before we finish to clear all layers, I'm disabling USD notification and I'm forcing a refresh after all layer are cleared.
Note :
Before clearing each layer, a warning dialog box is displayed and maya become idle so the Layer Editor get refresh and the selection list become invalidate. I spoke with Natalia and we conclude that displayed a warning dialog box when clearing a layer does not really make sense because this operation is undo-able and we don't display a warning when removing a layer. So I removed the confirmation box.