commit e3011638e20a5129e41d016b75d3a2af08b7b164
parent 6bad472d648665b6e0f84d7c981f718a16c4bd10
Author: Brad Werth <werth@efn.org>
Date: Wed, 26 Nov 2025 15:24:58 +0000
Bug 1972888 Part 3: Maintain the retain count of the nsCocoaWindow native window during runloops. r=mac-reviewers,mstange
Differential Revision: https://phabricator.services.mozilla.com/D272538
Diffstat:
2 files changed, 21 insertions(+), 9 deletions(-)
diff --git a/widget/cocoa/nsCocoaWindow.h b/widget/cocoa/nsCocoaWindow.h
@@ -523,7 +523,7 @@ class nsCocoaWindow final : public nsIWidget {
void UpdateFullscreenState(bool aFullScreen, bool aNativeMode);
nsresult DoMakeFullScreen(bool aFullScreen, bool aUseSystemTransition);
- BaseWindow* mWindow; // our cocoa window [STRONG]
+ BaseWindow* mWindow; // our cocoa window [STRONG]
// 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
diff --git a/widget/cocoa/nsCocoaWindow.mm b/widget/cocoa/nsCocoaWindow.mm
@@ -6050,16 +6050,22 @@ void nsCocoaWindow::ProcessTransitions() {
// Run a local run loop until it is safe to start a native fullscreen
// transition.
NSRunLoop* localRunLoop = [NSRunLoop currentRunLoop];
- while (mWindow && !CanStartNativeTransition() &&
+
+ // Retain our initial mWindow so it doesn't change under us. We'll
+ // release it after finishing the runloop.
+ NSWindow* initialWindow = mWindow;
+ [initialWindow retain];
+
+ while (!CanStartNativeTransition() &&
[localRunLoop runMode:NSDefaultRunLoopMode
beforeDate:[NSDate distantFuture]]) {
// This loop continues to process events until
- // CanStartNativeTransition() returns true or our native
- // window has been destroyed.
+ // CanStartNativeTransition() returns true.
}
// This triggers an async animation, so continue.
- [mWindow toggleFullScreen:nil];
+ [initialWindow toggleFullScreen:nil];
+ [initialWindow release];
continue;
}
break;
@@ -6085,16 +6091,22 @@ void nsCocoaWindow::ProcessTransitions() {
// Run a local run loop until it is safe to start a native
// fullscreen transition.
NSRunLoop* localRunLoop = [NSRunLoop currentRunLoop];
- while (mWindow && !CanStartNativeTransition() &&
+
+ // Retain our initial mWindow so it doesn't change under us. We'll
+ // release it after finishing the runloop.
+ NSWindow* initialWindow = mWindow;
+ [initialWindow retain];
+
+ while (!CanStartNativeTransition() &&
[localRunLoop runMode:NSDefaultRunLoopMode
beforeDate:[NSDate distantFuture]]) {
// This loop continues to process events until
- // CanStartNativeTransition() returns true or our native
- // window has been destroyed.
+ // CanStartNativeTransition() returns true.
}
// This triggers an async animation, so continue.
- [mWindow toggleFullScreen:nil];
+ [initialWindow toggleFullScreen:nil];
+ [initialWindow release];
continue;
} else {
mSuppressSizeModeEvents = true;