I have been building a macOS app with SwiftUI and Xcode. At some point I started facing a crash with following error:
The window has been marked as needing another Update Constraints in Window pass, but it has already had more Update Constraints in Window passes than there are views in the window.
I have reduced my project to a MWE that demonstrates the.
It still is quite long (about 50 lines of code) but I haven't been able to reduce it any further. In particular, the error seems to be dependent on the long String
in the ItemList
view. I have reduced its length and replaced as many characters by x
s as possible. Trying to further reduce the length of the string or replace more characters by x
s makes the crash go away. However, it's pretty clear, that the string cannot be what is wrong with the code.
Here is the MWE:
import SwiftUI
class Item: Identifiable {
}
struct ItemList: View {
@State var items = [Item()]
func loadMore() {
items.append(Item())
}
var body: some View {
List(items) { item in
VStack() {
Text("Test")
Text(String("""
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\
xx.net/xxxxxxx/xxxxxx xxxxxxxxx/xxxxxxxxxxx/xxxxxxxxx\
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxVfS\
YcPCuk9ogZKCnY7ZSkRG8K8bGTni4aAjUwFU4kbQAprBU1m4QL5Cj\
DayUt0QVyybMagRTRpghTl9ok1bxxxx=xxxxn353xxxxV7u2xxxxx\
xxxxxxxcWxz1GC0&cp=re346_mi_re_pb_p100&ch=reg&utm_med\
ium=email&utm_source=xxxxarchxxxx&utm_xxxxxxxx=xxxxx&\
utm_xxxx=xxxxx&utm_xxxxxxx=xxxxxxxxxxxxxxxxx> <xxxxx\
xxxxxxxxxxxxxxxxxxxxxxx/profile/xxxxxx
"""))
.lineLimit(3)
.font(.subheadline)
.foregroundStyle(.secondary)
}
.onAppear {
if item.id == items.last!.id {
loadMore()
}
}
}
}
}
struct MainWindow: View {
var body: some View {
NavigationSplitView {
List {
NavigationLink("List", destination: ItemList())
}
} detail: {
}
}
}
@main
struct TestApp: App {
var body: some Scene {
WindowGroup {
MainWindow()
}
}
}
I have copied the code into a fresh Xcode project and ran it to confirm that the crash is reproducible. The crash occurs right after clicking on the NavigationLink
in the sidebar.
To briefly walk you through the code, these are the main components: The TestApp
is very basic and only loads a MainWindow
instance. The MainWindow
employs a NavigationSplitView
with two columns (sidebar and detail pane). The sidebar contains a single NavigationLink
, when this is clicked, it is supposed to show a ItemList
inside the detail pane. The ItemList
has a single Item
when started, and whenever the last item of the list becomes visible, a new Item
is created and appended.
I am relatively new to Swift and have no further ideas how to proceed. Why is this code crashing? Xcode version is 16.0 and I am on macOS 15.0.1.
Edit: Regarding reproduction, it seems to be important that the newly created project is called Epistola
, it doesn't work if the project is called Test
. To facilitate reproduction I have zipped a freshly created project: https://www.icloud.com/iclouddrive/0f9HcLaLliyevRwu2O6KUiP_w
Edit: Xcode reports the following stack trace:
Thread 1 Queue : com.apple.main-thread (serial) #0 0x00000001910911fc in -[NSApplication _crashOnException:] () #1 0x0000000190ee055c in __62+[CATransaction(NSCATransaction) NS_setFlushesWithDisplayLink]_block_invoke () #2 0x000000019189be8c in ___NSRunLoopObserverCreateWithHandler_block_invoke () #3 0x000000018d2797a8 in __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ () #4 0x000000018d279694 in __CFRunLoopDoObservers () #5 0x000000018d278cc4 in __CFRunLoopRun () #6 0x000000018d278334 in CFRunLoopRunSpecific () #7 0x00000001986b10cc in RunCurrentEventLoopInMode () #8 0x00000001986b6ebc in ReceiveNextEventCommon () #9 0x00000001986b7020 in _BlockUntilNextEventMatchingListInModeWithFilter () #10 0x0000000190dbca70 in _DPSNextEvent () #11 0x00000001916e27b8 in -[NSApplication(NSEventRouting) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] () #12 0x0000000190dafb7c in -[NSApplication run] () #13 0x0000000190d8644c in NSApplicationMain () #14 0x00000001bb27c784 in merged generic specialization <SwiftUI.TestingAppDelegate> of function signature specialization <Arg[0] = Existential To Protocol Constrained Generic> of SwiftUI.runApp(__C.NSResponder & __C.NSApplicationDelegate) -> Swift.Never () #15 0x00000001bb70030c in SwiftUI.runApp<τ_0_0 where τ_0_0: SwiftUI.App>(τ_0_0) -> Swift.Never () #16 0x00000001bba0fbec in static SwiftUI.App.main() -> () () #17 0x0000000102f8cbf4 in static TestApp.$main() () #18 0x0000000102f8cca4 in main at /Users/void/Downloads/xcode-test/Epistola/Epistola/EpistolaApp.swift:53 #19 0x000000018ce10274 in start () Exception Backtrace#0 0x000000018d2eceb4 in __exceptionPreprocess () #1 0x000000018cdd2cd8 in objc_exception_throw () #2 0x000000018d2ecdb0 in +[NSException raise:format:] () #3 0x0000000191794428 in -[NSWindow(NSDisplayCycle) _postWindowNeedsUpdateConstraints] () #4 0x0000000190dd82b4 in -[NSView _informContainerThatSubviewsNeedUpdateConstraints] () #5 0x0000000190dd82b4 in -[NSView _informContainerThatSubviewsNeedUpdateConstraints] () #6 0x0000000191bdeee0 in -[_NSConstraintBasedLayoutHostingView _informContainerThatSubviewsNeedUpdateConstraints] () #7 0x0000000190dd82b4 in -[NSView _informContainerThatSubviewsNeedUpdateConstraints] () #8 0x0000000190dd82b4 in -[NSView _informContainerThatSubviewsNeedUpdateConstraints] () #9 0x0000000190dd82b4 in -[NSView _informContainerThatSubviewsNeedUpdateConstraints] () #10 0x0000000190dd82b4 in -[NSView _informContainerThatSubviewsNeedUpdateConstraints] () #11 0x0000000190dd82b4 in -[NSView _informContainerThatSubviewsNeedUpdateConstraints] () #12 0x0000000191bdeee0 in -[_NSConstraintBasedLayoutHostingView _informContainerThatSubviewsNeedUpdateConstraints] () #13 0x0000000190dd82b4 in -[NSView _informContainerThatSubviewsNeedUpdateConstraints] () #14 0x0000000190dd82b4 in -[NSView _informContainerThatSubviewsNeedUpdateConstraints] () #15 0x0000000190dd82b4 in -[NSView _informContainerThatSubviewsNeedUpdateConstraints] () #16 0x0000000190dd82b4 in -[NSView _informContainerThatSubviewsNeedUpdateConstraints] () #17 0x0000000190dd82b4 in -[NSView _informContainerThatSubviewsNeedUpdateConstraints] () #18 0x0000000190dd82b4 in -[NSView _informContainerThatSubviewsNeedUpdateConstraints] () #19 0x0000000190dd8238 in -[NSView setNeedsUpdateConstraints:] () #20 0x00000001bbb0fa00 in SwiftUI.NSHostingView.requestUpdate(after: Swift.Double) -> () () #21 0x0000000228bb293c in closure #1 () -> () in SwiftUI.ViewRendererHost.invalidateProperties(_: SwiftUI.ViewRendererHostProperties, mayDeferUpdate: Swift.Bool) -> () () #22 0x0000000228bb0268 in SwiftUI.ViewRendererHost.invalidateProperties(_: SwiftUI.ViewRendererHostProperties, mayDeferUpdate: Swift.Bool) -> () () #23 0x00000001bbb01928 in SwiftUI.NSHostingView.setFrameSize(__C.CGSize) -> () () #24 0x00000001bbb01998 in @objc SwiftUI.NSHostingView.setFrameSize(__C.CGSize) -> () () #25 0x0000000190df586c in -[NSView setFrame:] () #26 0x0000000190e431fc in NSViewActuallyUpdateFrameFromLayoutEngine () #27 0x0000000190e033ec in -[NSView layout] () #28 0x0000000190e4c3f8 in -[NSTableCellView layout] () #29 0x000000019185c430 in ___NSViewLayout_block_invoke () #30 0x0000000190dfe6f0 in NSPerformVisuallyAtomicChange () #31 0x0000000190e02f60 in _NSViewLayout () #32 0x0000000191852728 in __36-[NSView _layoutSubtreeWithOldSize:]_block_invoke () #33 0x0000000190dfe6f0 in NSPerformVisuallyAtomicChange () #34 0x0000000190e02ef4 in -[NSView _layoutSubtreeWithOldSize:] () #35 0x000000019185286c in __36-[NSView _layoutSubtreeWithOldSize:]_block_invoke () #36 0x0000000190dfe6f0 in NSPerformVisuallyAtomicChange () #37 0x0000000190e02ef4 in -[NSView _layoutSubtreeWithOldSize:] () #38 0x000000019185286c in __36-[NSView _layoutSubtreeWithOldSize:]_block_invoke () #39 0x0000000190dfe6f0 in NSPerformVisuallyAtomicChange () #40 0x0000000190e02ef4 in -[NSView _layoutSubtreeWithOldSize:] () #41 0x000000019185286c in __36-[NSView _layoutSubtreeWithOldSize:]_block_invoke () #42 0x0000000190dfe6f0 in NSPerformVisuallyAtomicChange () #43 0x0000000190e02ef4 in -[NSView _layoutSubtreeWithOldSize:] () #44 0x000000019185286c in __36-[NSView _layoutSubtreeWithOldSize:]_block_invoke () #45 0x0000000190dfe6f0 in NSPerformVisuallyAtomicChange () #46 0x0000000190e02ef4 in -[NSView _layoutSubtreeWithOldSize:] () #47 0x000000019185286c in __36-[NSView _layoutSubtreeWithOldSize:]_block_invoke () #48 0x0000000190dfe6f0 in NSPerformVisuallyAtomicChange () #49 0x0000000190e02ef4 in -[NSView _layoutSubtreeWithOldSize:] () #50 0x000000019185286c in __36-[NSView _layoutSubtreeWithOldSize:]_block_invoke () #51 0x0000000190dfe6f0 in NSPerformVisuallyAtomicChange () #52 0x0000000190e02ef4 in -[NSView _layoutSubtreeWithOldSize:] () #53 0x000000019185286c in __36-[NSView _layoutSubtreeWithOldSize:]_block_invoke () #54 0x0000000190dfe6f0 in NSPerformVisuallyAtomicChange () #55 0x0000000190e02ef4 in -[NSView _layoutSubtreeWithOldSize:] () #56 0x000000019185286c in __36-[NSView _layoutSubtreeWithOldSize:]_block_invoke () #57 0x0000000190dfe6f0 in NSPerformVisuallyAtomicChange () #58 0x0000000190e02ef4 in -[NSView _layoutSubtreeWithOldSize:] () #59 0x000000019185286c in __36-[NSView _layoutSubtreeWithOldSize:]_block_invoke () #60 0x0000000190dfe6f0 in NSPerformVisuallyAtomicChange () #61 0x0000000190e02ef4 in -[NSView _layoutSubtreeWithOldSize:] () #62 0x000000019185286c in __36-[NSView _layoutSubtreeWithOldSize:]_block_invoke () #63 0x0000000190dfe6f0 in NSPerformVisuallyAtomicChange () #64 0x0000000190e02ef4 in -[NSView _layoutSubtreeWithOldSize:] () #65 0x000000019185286c in __36-[NSView _layoutSubtreeWithOldSize:]_block_invoke () #66 0x0000000190dfe6f0 in NSPerformVisuallyAtomicChange () #67 0x0000000190e02ef4 in -[NSView _layoutSubtreeWithOldSize:] () #68 0x000000019185286c in __36-[NSView _layoutSubtreeWithOldSize:]_block_invoke () #69 0x0000000190dfe6f0 in NSPerformVisuallyAtomicChange () #70 0x0000000190e02ef4 in -[NSView _layoutSubtreeWithOldSize:] () #71 0x0000000191853308 in __56-[NSView _layoutSubtreeIfNeededAndAllowTemporaryEngine:]_block_invoke () #72 0x0000000190dfe6f0 in NSPerformVisuallyAtomicChange () #73 0x0000000190e02a84 in -[NSView _layoutSubtreeIfNeededAndAllowTemporaryEngine:] () #74 0x0000000190dfe6f0 in NSPerformVisuallyAtomicChange () #75 0x0000000190e02a14 in -[NSView layoutSubtreeIfNeeded] () #76 0x0000000191b34794 in -[NSWindow(NSConstraintBasedLayoutInternal) _layoutViewTree] () #77 0x0000000191b3491c in -[NSWindow(NSConstraintBasedLayoutInternal) layoutIfNeeded] () #78 0x0000000190e60320 in __NSWindowGetDisplayCycleObserverForLayout_block_invoke () #79 0x0000000190e5f8a0 in NSDisplayCycleObserverInvoke () #80 0x0000000190e5f500 in NSDisplayCycleFlush () #81 0x0000000195ca6f00 in CA::Transaction::run_commit_handlers () #82 0x0000000195ca5c68 in CA::Transaction::commit () #83 0x0000000190ee03e8 in __62+[CATransaction(NSCATransaction) NS_setFlushesWithDisplayLink]_block_invoke () #84 0x000000019189be8c in ___NSRunLoopObserverCreateWithHandler_block_invoke () #85 0x000000018d2797a8 in __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ () #86 0x000000018d279694 in __CFRunLoopDoObservers () #87 0x000000018d278cc4 in __CFRunLoopRun () #88 0x000000018d278334 in CFRunLoopRunSpecific () #89 0x00000001986b10cc in RunCurrentEventLoopInMode () #90 0x00000001986b6ebc in ReceiveNextEventCommon () #91 0x00000001986b7020 in _BlockUntilNextEventMatchingListInModeWithFilter () #92 0x0000000190dbca70 in _DPSNextEvent () #93 0x00000001916e27b8 in -[NSApplication(NSEventRouting) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] () #94 0x0000000190dafb7c in -[NSApplication run] () #95 0x0000000190d8644c in NSApplicationMain () #96 0x00000001bb27c784 in merged generic specialization <SwiftUI.TestingAppDelegate> of function signature specialization <Arg[0] = Existential To Protocol Constrained Generic> of SwiftUI.runApp(__C.NSResponder & __C.NSApplicationDelegate) -> Swift.Never () #97 0x00000001bb70030c in SwiftUI.runApp<τ_0_0 where τ_0_0: SwiftUI.App>(τ_0_0) -> Swift.Never () #98 0x00000001bba0fbec in static SwiftUI.App.main() -> () () #99 0x0000000102f8cbf4 in static TestApp.$main() () #100 0x0000000102f8cca4 in main at /Users/void/Downloads/xcode-test/Epistola/Epistola/EpistolaApp.swift:53 #101 0x000000018ce10274 in start ()
Test
, the error isn't reproducible, but when I call the projectEpistola
, it occurs. – GothaLayout
inside and outside theNavigationSplitView
to monitor the layout requests, turns out, layout requests inside theNavigationSplitView
are much more often and at some point it crashes. – Gotha