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.
Instead of trying to detect when to clean up the window based on the
NSView
's retain count, require window cleanup to be initiated explicitly viaWindow::close
,WindowHandle::close
, or[NSWindowDelegate windowShouldClose:]
(in non-parented mode; called when the user clicks the "X" button). This fixes the leaks and use-after-frees that can be caused by the inherent unreliability of the retain count logic.As discussed in #153, this change essentially means that the
NSView
created by Baseview will not be suitable as the top-level view for an Audio Unit, since the Baseview API now requires that child windows be cleaned up by an explicit call toWindowHandle::close
, and the only reliable signal for cleaning up an Audio Unit view is a call to[NSView dealloc]
. However, this does not mean that Baseview cannot be used in the context of an Audio Unit; it just means that plugin frameworks must implement a compatibility layer with a wrapperNSView
(which is the approach taken by JUCE).In order to implement this change:
WindowState
is stored in anRc
rather than aBox
.WindowHandle
holds anRc<WindowState>
so thatWindowHandle::close
can directly invoke window cleanup logic.WindowState::from_view
now returns a clone of theRc<WindowState>
held by theNSView
to ensure that it lives until the end of an event handler.NSView
is set as the window delegate, which allows it to receive thewindowShouldClose:
call when the user clicks the "X" button, upon which it will dispatch theWillClose
event and initiate window cleanup logic.Window::open_parented
andopen_blocking
no longerrelease
theNSView
immediately after attaching it. Instead, theNSView
is released as part of the cleanup logic inWindowInner::close
.Window::resize
now checks if the window is open to avoid using theNSView
after releasing it.release
method, theretain_count_after_build
field, theParentHandle
struct, and theclose_requested
flag have all been removed.