SwiftUI App crashing on iOS 14 - ContiguousArrayBuffer.swift

We are seeing a huge number of crashes coming from our iOS 14 users with the error Fatal error: Index out of range: file Swift/ContiguousArrayBuffer.swift, line 444

Following the stack I can see there is no array involved on my side and it actually appears to be a consequence of a setter on a @Published property.

The crash happens only on iOS 14.0 and iOS 14.0.1, while we don't have reports from our iOS 13 users, and it's not systematic, I'd say it happens 3 out of 10 times.

Can anyone please help me debug this issue?

Replies

Can you post a full Apple crash report for this? Please use a text attachment to avoid clogging up the timeline.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@apple.com"
  • Swift/ContiguousArrayBuffer.swift:580: Fatal error: Index out of range

    2021-09-28 20:38:14.956007-0500 CloudkitTemplate[1852:78799] Swift/ContiguousArrayBuffer.swift:580: Fatal error: Index out of range

    The same code worked fine the night before on three physical devices and iPhone 8 simulator. Twenty four hours later, getting this mysterious crash.

Add a Comment
Hi

I think we're having the same issue, did you find a solution ?

Our app is crashing (100% repro) on an iPhone 11 with iOS 14.0.0 (18A373). Alas I can't debug directly the app on this iPhone.
The crash happens when using a SwiftUI binding to go back in a NavigationView from a screen containing a picker. My guess is that picker is kept around for the duration of the animation but it's data is destroyed leading to a out of range when refreshing it's datasource.

Note that this trace doesn't contain any line of our code, the crash happens in SwiftUI / UIKit.

side note: the website refuse that I upload my trace as a txt file as you suggested to I'll paste it here.

Code Block
Crashed: com.apple.main-thread
0 libswiftCore.dylib 0x1ae6035b8 closure #1 in closure #1 in closure #1 in _assertionFailure(_:_:file:line:flags:) + 384
1 libswiftCore.dylib 0x1ae602ac4 _assertionFailure(_:_:file:line:flags:) + 472
2 libswiftCore.dylib 0x1ae5e0e94 _ArrayBuffer._checkInoutAndNativeTypeCheckedBounds(_:wasNativeTypeChecked:) + 212
3 libswiftCore.dylib 0x1ae5e74d8 Array.subscript.read + 160
4 libswiftCore.dylib 0x1ae5e740c protocol witness for Collection.subscript.read in conformance [A] + 68
5 SwiftUI 0x1b180f1e8 CoreCoordinator.pickerView(_:viewForRow:forComponent:reusing:) + 884
6 SwiftUI 0x1b180f3a4 @objc CoreCoordinator.pickerView(_:viewForRow:forComponent:reusing:) + 100
7 UIKitCore 0x1ad3861f8 -[UIPickerView tableView:cellForRowAtIndexPath:] + 560
8 UIKitCore 0x1ad37c584 -[UIPickerColumnView tableView:cellForRowAtIndexPath:] + 168
9 UIKitCore 0x1ad619580 -[UITableView _createPreparedCellForGlobalRow:withIndexPath:willDisplay:] + 644
10 UIKitCore 0x1ad5e5eac -[UITableView _updateVisibleCellsNow:] + 2476
11 UIKitCore 0x1ad603a90 -[UITableView layoutSubviews] + 356
12 UIKitCore 0x1ad37f52c 35-[UIPickerTableView layoutSubviews]_block_invoke + 92
13 UIKitCore 0x1ad918a60 +[UIView(Animation) performWithoutAnimation:] + 104
14 UIKitCore 0x1ad37f4c4 -[UIPickerTableView layoutSubviews] + 116
15 UIKitCore 0x1ad925dd4 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 2500
16 QuartzCore 0x1ade2f280 -[CALayer layoutSublayers] + 296
17 QuartzCore 0x1ade2f73c CA::Layer::layout_if_needed(CA::Transaction*) + 524
18 QuartzCore 0x1ade43b64 CA::Layer::layout_and_display_if_needed(CA::Transaction*) + 144
19 QuartzCore 0x1add8b114 CA::Context::commit_transaction(CA::Transaction*, double, double*) + 416
20 QuartzCore 0x1addb6418 CA::Transaction::commit() + 732
21 QuartzCore 0x1addb7778 CA::Transaction::observer_callback(CFRunLoopObserver*, unsigned long, void*) + 96
22 CoreFoundation 0x1aaa5a444 CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION + 36
23 CoreFoundation 0x1aaa54858 CFRunLoopDoObservers + 576
24 CoreFoundation 0x1aaa54e08 CFRunLoopRun + 1056
25 CoreFoundation 0x1aaa544bc CFRunLoopRunSpecific + 600
26 GraphicsServices 0x1c14d9820 GSEventRunModal + 164
27 UIKitCore 0x1ad3f8734 -[UIApplication _run] + 1072
28 UIKitCore 0x1ad3fde10 UIApplicationMain + 168
29 Applicant.testing 0x104e326a8 main + 20 (AppCoordinator.swift:20)
30 libdyld.dylib 0x1aa71be60 start + 4





My issue
I believe I am having the same issue with a user in 13.7 but I can't reproduce it. Our crash log is almost identical. Does anyone know if this issue has been resolved in newer releases?
This is just an index out of range assert. There are many potential causes of this, so it’s hard to offer concrete advice without seeing a full crash report. For example, luigidm wrote:

Following the stack I can see there is no array involved on my side
and it actually appears to be a consequence of a setter on a
@Published property.

but the backtrace posted by AlexisQapa and the crash report posted by siantz don’t correlate with that. Instead, they show a problem with the integration between SwiftUI and UIPickerView.

So, luigidm, I’m going to repeat my request that you post a full crash report. And AlexisQapa and siantz, I recommend that you start a specific thread about this issue and tag it with SwiftUI.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@apple.com"

getting this mysterious crash.

This doesn’t seem particularly mysterious. If you access an array out of bounds, Swift will trap with that message. For example, this code:

func main() {
    let a = ["Hello", "Cruel", "World!"]
    print(a[3])
}

main()

crashes with this message:

Swift/ContiguousArrayBuffer.swift:580: Fatal error: Index out of range
2021-09-29 10:41:23.310137+0100 MyTestTool[8120:741471] Swift/ContiguousArrayBuffer.swift:580: Fatal error: Index out of range

If you can reproduce the problem in Xcode, do so, then look at the backtrace in the Debug navigator to see how you got there.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

same error here...it is working with a small array

I'm not mutating the array