Fix issue with crashes during unpaired OpenWindow() / CloseWindow() calls to IGraphicsMac #1258
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.
This PR relates to #964.
If IGraphicsMac has a call to OpenWindow() whilst the window is already open this will call CloseWindow() and that call will trigger the view to call back into the delegate deleting the copy of IGraphics that is currently opening a window. This leads to crashes for unpaired OpenWindow() / CloseWindow() calls.
We require this call back to the delegate from the view's implementation of removeFromSuperview as this is the only place for some APIs we know that the window has closed. In other circumstances multiple calls to CloseWindow() are harmless but here the re-entrancy is problematic. The fix is thus to prevent this call only in instances where we know that we are in a call to OpenWindow() and the fix is entirely located in the Mac/View code as this is only an issue on this platform. It's not the nicest fix in the world, but it's low risk as I believe it is well isolated from other design decisions and scenarios.