Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@AlexHarker
Copy link
Collaborator

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.

@AlexHarker AlexHarker requested a review from olilarkin May 10, 2025 10:24
@olilarkin
Copy link
Member

#964 relates to AAX, but the comment in IGraphics_view.mm mentions AUv2 related code. Have you got a reproducible bug for this that doesn't involve EUCON/AAX?

It isn't very nice. Something about it doesn't feel quite right.

Could we not have an IGraphics::mIsClosing variable and test it, via a getter in IGEditorDelegate::CloseWindow() ?

@AlexHarker
Copy link
Collaborator Author

AlexHarker commented May 12, 2025

I've made the requested changes.

The comment about AUv2 is yours previously, and not mine - however, this part of the call structure interacts to create the issue. Essentially in AUv2 this is how we find out that the user has closed the window and thus destroy the IGraphics.

The EUCON error relates to two consecutive calls to the delegate OpenWindow() and the crash can be reproduced just by calling it twice in a row in the app host.

In this scenario the following happens:

  • OpenWindow() in IGraphics calls CloseWindow() in IGraphics to free old resources
  • CloseWindow() in IGraphics removes the view
  • That calls back into the delegate to CloseWindow() destroying IGraphics
  • We are still in the OpenWindow() call of the IGraphics

We could do as you say, but this is a Mac only issue and:
1 - it seems weird to propagate that up to the delegate
2 - it isn't that we are closing in general - we are closing at the IGraphics level (keeping IGraphics open) so putting it there is potentially confusing.
3 - there's already a closing check in the delegate

Another possibility is that we adapt the delegate to ignore calls to OpenWindow() if the window is already open (removing the CloseWindow() calls within OpenWindows() IGraphicsMac and IGraphicsIOS) - is that a better pattern?

@olilarkin
Copy link
Member

Another possibility is that we adapt the delegate to ignore calls to OpenWindow() if the window is already open (removing the CloseWindow() calls within OpenWindows() IGraphicsMac and IGraphicsIOS) - is that a better pattern?

That does sound a bit nicer. I think i'd prefer it!

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.

3 participants