Picker in NavigationLink’ed view crashes

If I tap “Picks >”, then tap “< View3”, then tap “< View2”, the app crashes.


How can I fix this?


Thanks



////



import SwiftUI


struct ContentView: View {

var body: some View {

View2()

}

}


struct View2: View {

var body: some View {

NavigationView {

List {

NavigationLink(destination: View3()) {

Text("Link")

}

}

.navigationBarTitle(Text("View2"), displayMode: .inline)

}

}

}


struct View3: View {

@State private var picked = 0

static let picks = ["Pick1", "Pick2"]

var body: some View {

//NavigationView { //1.crash without this line. 2. it looks odd with this though

Form {

Picker("Picks", selection: $picked) {

ForEach(0 ..< Self.picks.count) {

Text(Self.picks[$0])

}

}

}

.navigationBarTitle(Text("View3"), displayMode: .inline)

//}

}

}


struct ContentView_Previews: PreviewProvider {

static var previews: some View {

ContentView()

}

}



////



(lldb) bt

* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)

frame #0: 0x00007fff2c2270bb SwiftUI`SwiftUI._VariadicView_Children.subscript.getter : (Swift.Int) -> SwiftUI._VariadicView_Children.Element + 235

frame #1: 0x00007fff2c2281d6 SwiftUI`protocol witness for Swift.Collection.subscript.read : (A.Index) -> A.Element in conformance SwiftUI._VariadicView_Children : Swift.Collection in SwiftUI + 38

frame #2: 0x00007fff2c450f31 SwiftUI`SwiftUI.ForEach.IDGenerator.makeID(data: A, index: A.Index, offset: Swift.Int) -> B + 289

frame #3: 0x00007fff2c453052 SwiftUI`SwiftUI.(DynamicContentState in _4103B39A1695DB4F1CFCE0B3FB46910F).update(view: SwiftUI.ForEach<A, B, C>) -> () + 1362

frame #4: 0x00007fff2c4565dd SwiftUI`SwiftUI.(DynamicContentState in _4103B39A1695DB4F1CFCE0B3FB46910F).Info.Init.apply(SwiftUI.ForEach<A, B, C>) -> SwiftUI.(DynamicContentState in _4103B39A1695DB4F1CFCE0B3FB46910F)<A, B, C>.Info + 29

frame #5: 0x00007fff2c456b40 SwiftUI`protocol witness for static AttributeGraph.UntypedAttribute._update(_: Swift.UnsafeMutableRawPointer, graph: __C.AGGraphRef, attribute: __C.AGAttribute) -> () in conformance SwiftUI.(DynamicContentState in _4103B39A1695DB4F1CFCE0B3FB46910F)<A, B, C>.Info.Init : AttributeGraph.UntypedAttribute in SwiftUI + 192

frame #6: 0x00007fff2f8f1849 AttributeGraph`partial apply forwarder + 25

frame #7: 0x00007fff2f8d9255 AttributeGraph`AG::Graph::UpdateStack::update() + 1111

frame #8: 0x00007fff2f8d9513 AttributeGraph`AG::Graph::update_attribute(unsigned int, bool) + 377

frame #9: 0x00007fff2f8dc698 AttributeGraph`AG::Graph::value_ref(AG::attribute_t, AGTypeID, bool*) + 84

frame #10: 0x00007fff2f8e4324 AttributeGraph`AG::Graph::EntryExit::update_entry() const + 60

frame #11: 0x00007fff2f8d9255 AttributeGraph`AG::Graph::UpdateStack::update() + 1111

frame #12: 0x00007fff2f8d9513 AttributeGraph`AG::Graph::update_attribute(unsigned int, bool) + 377

frame #13: 0x00007fff2f8de131 AttributeGraph`AG::Subgraph::update(unsigned int) + 929

frame #14: 0x00007fff2c10d100 SwiftUI`SwiftUI.ViewGraph.(runTransaction in _D63C4EB7F2B205694B6515509E76E98B)(in: __C.AGGraphRef) -> () + 224

frame #15: 0x00007fff2c10d517 SwiftUI`closure #1 (__C.AGGraphRef) -> (prefs: Swift.Bool, idealSize: Swift.Bool, outputs: SwiftUI.ViewGraph.Outputs) in SwiftUI.ViewGraph.updateOutputs(at: SwiftUI.Time) -> () + 103

frame #16: 0x00007fff2c10d1d1 SwiftUI`SwiftUI.ViewGraph.updateOutputs(at: SwiftUI.Time) -> () + 145

frame #17: 0x00007fff2c4af579 SwiftUI`closure #1 () -> () in closure #1 () -> () in (extension in SwiftUI):SwiftUI.ViewRendererHost.render(interval: Swift.Double, updateDisplayList: Swift.Bool) -> () + 1001

frame #18: 0x00007fff2c4aef8a SwiftUI`closure #1 () -> () in (extension in SwiftUI):SwiftUI.ViewRendererHost.render(interval: Swift.Double, updateDisplayList: Swift.Bool) -> () + 634

frame #19: 0x00007fff2c4a4274 SwiftUI`(extension in SwiftUI):SwiftUI.ViewRendererHost.render(interval: Swift.Double, updateDisplayList: Swift.Bool) -> () + 436

frame #20: 0x00007fff2c00a8ee SwiftUI`closure #1 () -> () in SwiftUI._UIHostingView.requestImmediateUpdate() -> () + 62

frame #21: 0x00007fff2c004849 SwiftUI`reabstraction thunk helper from @escaping @callee_guaranteed () -> () to @escaping @callee_unowned @convention(block) () -> () + 25

frame #22: 0x000000010f1dadf8 libdispatch.dylib`_dispatch_call_block_and_release + 12

frame #23: 0x000000010f1dbd6c libdispatch.dylib`_dispatch_client_callout + 8

frame #24: 0x000000010f1e9e24 libdispatch.dylib`_dispatch_main_queue_callback_4CF + 1500

frame #25: 0x00007fff23b0ce49 CoreFoundation`__CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9

frame #26: 0x00007fff23b07aa9 CoreFoundation`__CFRunLoopRun + 2329

frame #27: 0x00007fff23b06e66 CoreFoundation`CFRunLoopRunSpecific + 438

frame #28: 0x00007fff38346bb0 GraphicsServices`GSEventRunModal + 65

frame #29: 0x00007fff47578dd0 UIKitCore`UIApplicationMain + 1621

* frame #30: 0x000000010ed7fbeb HelloSwiftUI`main at AppDelegate.swift:12:7

frame #31: 0x00007fff516ecd29 libdyld.dylib`start + 1

frame #32: 0x00007fff516ecd29 libdyld.dylib`start + 1

(lldb)

Replies

more info:


2019-10-17 15:29:11.635759+0800 HelloSwiftUI[3928:189392] [TableView] Warning once only: UITableView was told to layout its visible cells and other contents without being in the view hierarchy (the table view or one of its superviews has not been added to a window). This may cause bugs by forcing views inside the table view to load and perform layout without accurate information (e.g. table view bounds, trait collection, layout margins, safe area insets, etc), and will also cause unnecessary performance overhead due to extra layout passes. Make a symbolic breakpoint at UITableViewAlertForLayoutOutsideViewHierarchy to catch this in the debugger and see what caused this to occur, so you can avoid this action altogether if possible, or defer it until the table view has been added to a window. Table view: <_TtC7SwiftUIP33_BFB370BA5F1BADDC9D83021565761A4925UpdateCoalescingTableView: 0x7f8302931e00; baseClass = UITableView; frame = (0 0; 375 812); clipsToBounds = YES; gestureRecognizers = <NSArray: 0x600003bc49f0>; layer = <CALayer: 0x600003517d60>; contentOffset: {0, -140}; contentSize: {375, 161.00000000000003}; adjustedContentInset: {140, 0, 34, 0}; dataSource: <_TtGC7SwiftUIP13$7fff2c69bad819ListCoreCoordinatorGVS_20SystemListDataSourceOs5Never_GOS_19SelectionManagerBoxS2___: 0x7f83024724c0>>

(lldb)

The code as posted above isn't crashing for me with Xcode 11.1 or 11.2 beta 2. Is this only happening on-device for you?

That particular issue is just noise; it happens on all SwiftUI table views. Firing off a bug report to https://feedbackassistant.apple.com/ would help raise the priority of a fix, though.

Hi Jim,


It happens on Xcode Version 11.1 (11A1027).


I haven't tried the beta version. Is it ok to have two versions of Xcode on same macOS machine? The commands: xcode-***, clang, clang++, lldb and linkers, libtools of both versons of Xcode, will they all be good?


Thanks

I am facing a similar issue.


----> "precondition failure: imported node deleted before its value was read: 92"


and sometimes I see 91


(Does not crash on the simulator, but only on HW currently on iOS 13.1.3)



struct ContentView: View {


@State var storeId = ""

@State var purchase = ""


var body: some View {


NavigationView {

if self.purchase.isEmpty {

if self.storeId.isEmpty {

StoreSelectorView(storeId: $storeId)

} else {

FruitPurchaserView(purchase: $purchase)

}

} else {

ReceiptView(purchase: purchase)

}

}

}

}




struct StoreSelectorView: View {

@Binding var storeId: String


var body: some View {


VStack {

Button(action: finalizeSelection ) {

Text("Select Nearest Store")

}

}

}



func finalizeSelection() {

self.storeId = "CA999"

}

}




struct FruitPurchaserView: View {


@Binding var purchase: String


@State var selection: String = "DURIAN"

@State var fruits: Array<String> = ["APPLES", "BANANAS", "CAROTS", "DURIAN"]

@State var weight = ""


var body: some View {


Form {

Section(header: Text("What are you buying")) {


Picker(selection: $selection, label: Text("Fruit") ) {

ForEach(fruits, id: \.self) { fruit in

Text(fruit)

}

}


HStack {

Text("How many lbs?")

Spacer()

TextField("000", text: $weight )

.keyboardType(.numberPad)

}

}

Section {

HStack {

Spacer()

Button(action: handlePurchase ) {

VStack {

Text("Buy fruit")

Text("In-app purchase")

}

}.frame(width: 200)

Spacer()

}

}

}

.navigationBarTitle("Fruit market")

}


func handlePurchase() {

self.purchase = "\(self.selection) \(weight)lbs"


}

}






and




struct ReceiptView: View {


@State var purchase = ""


var body: some View {

Text("Subscription: \(self.purchase)")

}


}




IMPORTANT NOTE: Also, it all works fine if I do any of the following

Remove the Picker from FruitPurchaseView



Thread 1 Queue : com.apple.main-thread (serial)

#0 0x0000000199ce4ebc in __pthread_kill ()

#1 0x0000000199c04c1c in pthread_kill$VARIANT$armv81 ()

#2 0x0000000199b54824 in abort ()

#3 0x00000001c41393c0 in AG::precondition_failure(char const*, ...) ()

#4 0x00000001c411568c in AG::Graph::EntryExit::update_entry() const ()

#5 0x00000001c410aa60 in AG::Graph::UpdateStack::update() ()

#6 0x00000001c410ad24 in AG::Graph::update_attribute(unsigned int, bool) ()

#7 0x00000001c410e290 in AG::Graph::input_value_ref_slow(unsigned int, unsigned int, AGTypeID, bool*) ()

#8 0x00000001cfe81cd0 in specialized AnimatableAttribute.update(context:) ()

#9 0x00000001cfdcc310 in partial apply for specialized ()

#10 0x00000001c410aa60 in AG::Graph::UpdateStack::update() ()

#11 0x00000001c410ad24 in AG::Graph::update_attribute(unsigned int, bool) ()

#12 0x00000001c410fa0c in AG::Subgraph::update(unsigned int) ()

#13 0x00000001cfacd838 in ViewGraph.runTransaction(in:) ()

#14 0x00000001cfacdb64 in closure #1 in ViewGraph.updateOutputs(at:) ()

#15 0x00000001cfacd8ec in ViewGraph.updateOutputs(at:) ()

#16 0x00000001cfe342bc in closure #1 in closure #1 in ViewRendererHost.render(interval:updateDisplayList:) ()

#17 0x00000001cfe33d24 in closure #1 in ViewRendererHost.render(interval:updateDisplayList:) ()

#18 0x00000001cfe2a600 in ViewRendererHost.render(interval:updateDisplayList:) ()

#19 0x00000001cf9dcce8 in closure #1 in _UIHostingView.requestImmediateUpdate() ()

#20 0x00000001cf9d91b8 in thunk for @escaping @callee_guaranteed () -> () ()

#21 0x0000000102b65828 in _dispatch_call_block_and_release ()

#22 0x0000000102b66c04 in _dispatch_client_callout ()

#23 0x0000000102b74c64 in _dispatch_main_queue_callback_4CF ()

#24 0x0000000199e6a3c4 in __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ ()

#25 0x0000000199e653b8 in __CFRunLoopRun ()

#26 0x0000000199e648bc in CFRunLoopRunSpecific ()

#27 0x00000001a3cd0328 in GSEventRunModal ()

#28 0x000000019defa6d4 in UIApplicationMain ()

#29 0x0000000102a78448 in main at /Users/starlord/github/CRASH_REPRODUCE/CRASH_REPRODUCE/AppDelegate.swift:12

#30 0x0000000199cef460 in start ()

Enqueued from com.apple.main-thread (Thread 1) Queue : com.apple.main-thread (serial)

#0 0x0000000102b6b058 in dispatch_async ()

#1 0x00000001ce84f624 in OS_dispatch_queue.async(group:qos:flags:execute:) ()

#2 0x00000001cf9dcba8 in _UIHostingView.requestImmediateUpdate() ()

#3 0x00000001cf9dc694 in _UIHostingView.requestUpdate(after:) ()

#4 0x00000001cffacf34 in _UIHostingView.didMoveToWindow() ()

#5 0x00000001cffad08c in @objc _UIHostingView.didMoveToWindow() ()

#6 0x000000019e37c2b0 in -[UIView(Internal) _didMoveFromWindow:toWindow:] ()

#7 0x000000019e37be28 in -[UIView(Internal) _didMoveFromWindow:toWindow:] ()

#8 0x000000019e37be28 in -[UIView(Internal) _didMoveFromWindow:toWindow:] ()

#9 0x000000019e37be28 in -[UIView(Internal) _didMoveFromWindow:toWindow:] ()

#10 0x000000019e30227c in -[UIScrollView _didMoveFromWindow:toWindow:] ()

#11 0x000000019e37be28 in -[UIView(Internal) _didMoveFromWindow:toWindow:] ()

#12 0x000000019e3701d4 in __45-[UIView(Hierarchy) _postMovedFromSuperview:]_block_invoke ()

#13 0x000000019e3700bc in -[UIView(Hierarchy) _postMovedFromSuperview:] ()

#14 0x000000019e36e3a4 in __UIViewWasRemovedFromSuperview ()

#15 0x000000019e36de84 in -[UIView(Hierarchy) removeFromSuperview] ()

#16 0x00000001cfc12c40 in PlatformViewHost.removeFromSuperview() ()

#17 0x00000001cfc12c74 in @objc PlatformViewHost.removeFromSuperview() ()

#18 0x00000001cfc6d9f8 in DisplayList.ViewUpdater.Container.removeRemaining(viewCache:) ()

#19 0x00000001cfc6d608 in DisplayList.ViewUpdater.update(rootView:from:version:) ()

#20 0x00000001cf9dcd70 in _UIHostingView.renderDisplayList(_:version:) ()

#21 0x00000001cfe33e44 in closure #1 in ViewRendererHost.render(interval:updateDisplayList:) ()

#22 0x00000001cfe2a600 in ViewRendererHost.render(interval:updateDisplayList:) ()

#23 0x00000001cffad22c in _UIHostingView.layoutSubviews() ()

#24 0x00000001cffad258 in @objc _UIHostingView.layoutSubviews() ()

#25 0x000000019e385270 in -[UIView(CALayerDelegate) layoutSublayersOfLayer:] ()

#26 0x00000001a08715f8 in -[CALayer layoutSublayers] ()

#27 0x00000001a0875e28 in CA::Layer::layout_if_needed(CA::Transaction*) ()

#28 0x00000001a0881894 in CA::Layer::layout_and_display_if_needed(CA::Transaction*) ()

#29 0x00000001a07ca9f0 in CA::Context::commit_transaction(CA::Transaction*, double) ()

#30 0x00000001a07f4890 in CA::Transaction::commit() ()

#31 0x00000001a07f5284 in CA::Transaction::observer_callback(__CFRunLoopObserver*, unsigned long, void*) ()

#32 0x0000000199e69c48 in __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ ()

#33 0x0000000199e64b34 in __CFRunLoopDoObservers ()

#34 0x0000000199e65100 in __CFRunLoopRun ()

#35 0x0000000199e648bc in CFRunLoopRunSpecific ()

#36 0x00000001a3cd0328 in GSEventRunModal ()

#37 0x000000019defa6d4 in UIApplicationMain ()

#38 0x0000000102a78448 in main at /Users/starlord/github/CRASH_REPRODUCE/CRASH_REPRODUCE/AppDelegate.swift:12

#39 0x0000000199cef460 in start ()