Skip to content

Commit

Permalink
No Issue - Make nsCocoaWindow hold a death grip on its native window …
Browse files Browse the repository at this point in the history
  • Loading branch information
dbsoft committed Nov 30, 2024
1 parent cd78019 commit 0887abe
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
7 changes: 6 additions & 1 deletion widget/cocoa/nsCocoaWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -412,8 +412,13 @@ class nsCocoaWindow : public nsBaseWidget, public nsPIWidgetCocoa
nsIWidget* mParent; // if we're a popup, this is our parent [WEAK]
nsIWidget* mAncestorLink; // link to traverse ancestors [WEAK]
BaseWindow* mWindow; // our cocoa window [STRONG]
BaseWindow* mClosedRetainedWindow; // a second strong reference to our
// window upon closing it, held through our destructor. This is useful
// to ensure that macOS run loops which reference the window will still
// have something to point to even if they don't use proper retain and
// release patterns.
WindowDelegate* mDelegate; // our delegate for processing window msgs [STRONG]
RefPtr<nsMenuBarX> mMenuBar;
RefPtr<nsMenuBarX> mMenuBar;
NSWindow* mSheetWindowParent; // if this is a sheet, this is the NSWindow it's attached to
nsChildView* mPopupContentView; // if this is a popup, this is its content widget
// if this is a toplevel window, and there is any ongoing fullscreen
Expand Down
9 changes: 9 additions & 0 deletions widget/cocoa/nsCocoaWindow.mm
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ static void RollUpPopups()
: mParent(nullptr)
, mAncestorLink(nullptr)
, mWindow(nil)
, mClosedRetainedWindow(nil)
, mDelegate(nil)
, mSheetWindowParent(nil)
, mPopupContentView(nil)
Expand Down Expand Up @@ -147,6 +148,12 @@ static void RollUpPopups()
// We want to unhook the delegate here because we don't want events
// sent to it after this object has been destroyed.
[mWindow setDelegate:nil];
// Closing the window will also release it. Our second reference will
// keep it alive through our destructor. Release any reference we might
// have from an earlier call to DestroyNativeWindow, then create a new
// one.
[mClosedRetainedWindow autorelease];
mClosedRetainedWindow = [mWindow retain];
[mWindow close];
mWindow = nil;
[mDelegate autorelease];
Expand Down Expand Up @@ -181,6 +188,8 @@ static void RollUpPopups()
DestroyNativeWindow();
}

[mClosedRetainedWindow release];

NS_IF_RELEASE(mPopupContentView);

// Deal with the possiblity that we're being destroyed while running modal.
Expand Down

0 comments on commit 0887abe

Please sign in to comment.