Repository navigation
Description
Current behavior
On Skia macOS, a closed secondary UNOWindow (NSWindow) is deallocated while managed code and AppKit still reference it. A later autorelease-pool drain on the main thread then releases the freed object and the process dies with Segmentation fault: 11.
This is a pure crash with no managed exception. In CI it hit the macOS WebGPU runtime-test lane in about 16 of 19 runs, always some minutes after a multi-window test closed its secondary window. It also hit the Metal lane once, when a test called Minimize() and then Window.Close() on a secondary window (seen while working on #25203).
Crash signature in every core dump (main thread):
objc_release
<- AutoreleasePoolPage::releaseUntil
<- objc_autoreleasePoolPop
<- -[NSAutoreleasePool drain]
<- -[NSApplication run]
The fault address is the garbage isa of the freed object plus 0x20 (KERN_INVALID_ADDRESS). The freed pointer is the same value that a managed MacOSNativeOverlappedPresenter._handle and MacOSDragDropExtension._windowHandle still hold, so it is a former secondary window. Window addresses are also reused by later windows, which shows closed windows really are freed.
Expected behavior
Closing a window should leave no dangling native references. The object stays alive until the managed side has dropped its handle, and the app never crashes later because of a window that was closed earlier.
How to reproduce it
Confirmed from CI core dumps and by reading the source. I could not reproduce it locally because I have no Mac available, so the trigger below is the CI pattern, not a verified minimal repro.
- Run the Skia macOS desktop head (the crash is much more frequent with
UNO_WEBGPU=1). - Open one or more secondary windows, let them render (with WebGPU, a surface gets configured for each), then close them via
Window.Close(). Closing a minimized window (Minimize()thenClose()) also triggers it. - Keep the app running and do more native-view work on the main thread (in CI:
WebView2.ExecuteScriptAsynctests, or full-windowMediaPlayerElementtests). - After some time (seconds to minutes) the process segfaults in
-[NSApplication run].
Workaround
None in-app. Avoid closing secondary windows on macOS.
Works on UWP/WinUI
N/A (macOS-specific native lifetime bug).
Environment
- Other
- Source inspected on master
0599dada9e9; CI core dumps came from a build of1e8317593f4(net10.0 desktop, wgpu-native v29.0.1.1)
Affected platforms
Skia (macOS desktop). Windows/Linux not affected.
Anything else
Root cause (partial, confirmed by code inspection on master 0599dada9e9, not by a runtime repro):
UNOWindowkeeps the NSWindow defaultreleasedWhenClosed = YESunder ARC. Nothing in the native project ever sets it toNO.- The window is retained only by the static
windowsset: declared at L13, added at L356 and removed only in-dealloc(L1290). That reference is never dropped on close. - Close goes through
[window performClose:nil](L411) andwindowWillClose:(L1656), which only removes screen observers and calls back to managed code. AppKit then performs its extra close-time release, which consumes thewindowsset's reference, so the window is freed while the managed side still holds the raw pointer (MacOSNativeOverlappedPresenter._handle). - The release that finally crashes comes from a late autorelease/retain of the dead window by something else. That holder is not pinned (the Metal lane rarely hits it). Candidates: the
MTKViewused for external present, wgpu's occlusion check (layer.delegate.window.occlusionState), AppKit accessibility/KVO tables, and the Dock tile for minimized windows.
Suggested fix: set releasedWhenClosed = NO in UNOWindow's initializer, detach the rendering view in windowWillClose:, and drop the windows reference asynchronously after close (for example via dispatch_async on the main queue), so nothing frees a window that managed code still points at. A fix is in progress and still needs a CI run of the macOS WebGPU lane to confirm.
Related: #25203 (a PR whose new close-a-minimized-window test hit this crash on the Metal lane; a symptom there, not the same change).
Activity
MartinZikmund commentedon Oct 12, 2026
A fix is in progress in #25201.