Crash: IndexPath.section.getter + 168

Hello everyone!

My app is getting a crash in the tableView(_:trailingSwipeActionsConfigurationForRowAt:) function.
Apparently, the app is crashing when trying to get the indexPath.section value. I am attaching the crash log.
This is not reproducible for me. I have the hunch that this might be related to some accessibility feature, but I have not been able to corroborate it yet.

I am not sure how to solve this issue or how to move forward since I still don't know what is causing the app.

Any advice or guidance is really appreciated. Thank you!

Code Block Crashed: com.apple.main-threadEXC_BREAKPOINT 0x00000001bd99e0c8Crashed: com.apple.main-thread0  libswiftUIKit.dylib            0x1bd99e0c8 IndexPath.section.getter + 1681  MyApp                          0x1033697a4 TableDelegate.tableView(_:trailingSwipeActionsConfigurationForRowAt:) + 337 (TableDelegate.swift:337)2  MyApp                          0x103369e58 @objc TableDelegate.tableView(_:trailingSwipeActionsConfigurationForRowAt:) + 4316896856 (<compiler-generated>:4316896856)3  UIKitCore                      0x1ad80b9cc -[UITableView _trailingSwipeConfigurationAtIndexPath:fromRemoveButton:] + 18924  UIKit                          0x1f0935c34 -[UITableViewCellAccessibility _privateAccessibilityCustomActions] + 5405  UIAccessibility                0x1bd9d8854 -[NSObject(AXPrivCategory) _retrieveCustomActionsForElement:] + 686  UIAccessibility                0x1bd9d8b0c -[NSObject(AXPrivCategory) _accessibilityCustomActions] + 2207  UIAccessibility                0x1bd9f990c -[NSObjectAccessibility accessibilityRespondsToUserInteraction] + 4248  UIKit                          0x1f0952f6c -[UIViewAccessibility accessibilityRespondsToUserInteraction] + 1249  UIKit                          0x1f08f3440 -[UILabelAccessibility accessibilityRespondsToUserInteraction] + 12010 UIKit                          0x1f0959678 -[UIViewAccessibility _isEligibleForFocusInteraction] + 12411 UIKitCore                      0x1ad07f4e4 _UIFocusEnvironmentIsEligibleForFocusInteraction + 6412 UIKitCore                      0x1ad0acb44 UIFocusMapRecurseSearchForFocusSystemInEligibleContainer + 14813 UIKitCore                      0x1ad0c30f8 -[_UIFocusMapSnapshot addRegionsInContainer:] + 6414 UIKitCore                      0x1ad0c32fc -[_UIFocusMapSnapshot addRegionsInContainers:] + 19615 UIKitCore                      0x1adad78cc -[UIView _searchForFocusRegionsInContext:] + 92416 UIKitCore                      0x1ad0c3178 -[_UIFocusMapSnapshot addRegionsInContainer:] + 19217 UIKitCore                      0x1ad0c32fc -[_UIFocusMapSnapshot addRegionsInContainers:] + 19650 UIKitCore                      0x1ada9595c -[_UIAfterCACommitBlock run] + 6451 UIKitCore                      0x1ad5ff79c _runAfterCACommitDeferredBlocks + 29652 UIKitCore                      0x1ad5eeb4c _cleanUpAfterCAFlushAndRunDeferredBlocks + 20053 UIKitCore                      0x1ad620260 _afterCACommitHandler + 7654 CoreFoundation                 0x1aad2fecc CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION + 3255 CoreFoundation                 0x1aad2a5b0 CFRunLoopDoObservers + 60456 CoreFoundation                 0x1aad2aaf8 __CFRunLoopRun + 96057 CoreFoundation                 0x1aad2a200 CFRunLoopRunSpecific + 57258 GraphicsServices               0x1c0e25598 GSEventRunModal + 16059 UIKitCore                      0x1ad5f0004 -[UIApplication _run] + 105260 UIKitCore                      0x1ad5f55d8 UIApplicationMain + 16461 MyApp                          0x102d7d654 main + 16 (AppDelegate.swift:16)62 libdyld.dylib                  0x1aaa09598 start + 4

Crashed: com.apple.main-thread
EXC_BREAKPOINT 0x00000001bd99e0c8

Crashed: com.apple.main-thread
0  libswiftUIKit.dylib            0x1bd99e0c8 IndexPath.section.getter + 168
1  MyApp                          0x1033697a4 TableDelegate.tableView(_:trailingSwipeActionsConfigurationForRowAt:) + 337 (TableDelegate.swift:337)
2  MyApp                          0x103369e58 @objc TableDelegate.tableView(_:trailingSwipeActionsConfigurationForRowAt:) + 4316896856 (<compiler-generated>:4316896856)
3  UIKitCore                      0x1ad80b9cc -[UITableView _trailingSwipeConfigurationAtIndexPath:fromRemoveButton:] + 1892
4  UIKit                          0x1f0935c34 -[UITableViewCellAccessibility _privateAccessibilityCustomActions] + 540
5  UIAccessibility                0x1bd9d8854 -[NSObject(AXPrivCategory) _retrieveCustomActionsForElement:] + 68
6  UIAccessibility                0x1bd9d8b0c -[NSObject(AXPrivCategory) _accessibilityCustomActions] + 220
7  UIAccessibility                0x1bd9f990c -[NSObjectAccessibility accessibilityRespondsToUserInteraction] + 424
8  UIKit                          0x1f0952f6c -[UIViewAccessibility accessibilityRespondsToUserInteraction] + 124
9  UIKit                          0x1f08f3440 -[UILabelAccessibility accessibilityRespondsToUserInteraction] + 120
10 UIKit                          0x1f0959678 -[UIViewAccessibility _isEligibleForFocusInteraction] + 124
11 UIKitCore                      0x1ad07f4e4 _UIFocusEnvironmentIsEligibleForFocusInteraction + 64
12 UIKitCore                      0x1ad0acb44 __UIFocusMapRecurseSearchForFocusSystemInEligibleContainer + 148
13 UIKitCore                      0x1ad0c30f8 -[_UIFocusMapSnapshot addRegionsInContainer:] + 64
14 UIKitCore                      0x1ad0c32fc -[_UIFocusMapSnapshot addRegionsInContainers:] + 196
15 UIKitCore                      0x1adad78cc -[UIView _searchForFocusRegionsInContext:] + 924
16 UIKitCore                      0x1ad0c3178 -[_UIFocusMapSnapshot addRegionsInContainer:] + 192
17 UIKitCore                      0x1ad0c32fc -[_UIFocusMapSnapshot addRegionsInContainers:] + 196
18 UIKitCore                      0x1adad78cc -[UIView _searchForFocusRegionsInContext:] + 924
19 UIKitCore                      0x1ad0c3178 -[_UIFocusMapSnapshot addRegionsInContainer:] + 192
20 UIKitCore                      0x1ad0c32fc -[_UIFocusMapSnapshot addRegionsInContainers:] + 196
21 UIKitCore                      0x1adad78cc -[UIView _searchForFocusRegionsInContext:] + 924
22 UIKitCore                      0x1ad0c3178 -[_UIFocusMapSnapshot addRegionsInContainer:] + 192
23 UIKitCore                      0x1ad0c32fc -[_UIFocusMapSnapshot addRegionsInContainers:] + 196
24 UIKitCore                      0x1adad78cc -[UIView _searchForFocusRegionsInContext:] + 924
25 UIKitCore                      0x1ad0c3178 -[_UIFocusMapSnapshot addRegionsInContainer:] + 192
26 UIKitCore                      0x1ad0c32fc -[_UIFocusMapSnapshot addRegionsInContainers:] + 196
27 UIKitCore                      0x1adad78cc -[UIView _searchForFocusRegionsInContext:] + 924
28 UIKitCore                      0x1ad0c3178 -[_UIFocusMapSnapshot addRegionsInContainer:] + 192
29 UIKitCore                      0x1ad0c29b0 -[_UIFocusMapSnapshot _capture] + 280
30 UIKitCore                      0x1ad0c20c8 -[_UIFocusMapSnapshot _initWithSnapshotter:mapArea:searchArea:] + 492
31 UIKitCore                      0x1ad0c3ef4 -[_UIFocusMapSnapshotter captureSnapshot] + 220
32 UIKitCore                      0x1ad0b9b1c -[_UIFocusMap _defaultFocusItemInEnvironment:limitScopeUsingFocusPreferences:] + 212
33 UIKitCore                      0x1ad0910e8 -[_UIFocusEnvironmentPreferenceEnumerationContext _inferPreferencesForEnvironment:] + 152
34 UIKitCore                      0x1ad090c84 -[_UIFocusEnvironmentPreferenceEnumerationContext _resolvePreferredFocusEnvironments] + 128
35 UIKitCore                      0x1ad090bc4 -[_UIFocusEnvironmentPreferenceEnumerationContext prefersNothingFocused] + 40
36 UIKitCore                      0x1ad0918ec _enumeratePreferredFocusEnvironments + 184
37 UIKitCore                      0x1ad091a10 _enumeratePreferredFocusEnvironments + 476
38 UIKitCore                      0x1ad091a10 _enumeratePreferredFocusEnvironments + 476
39 UIKitCore                      0x1ad091a10 _enumeratePreferredFocusEnvironments + 476
40 UIKitCore                      0x1ad091a10 _enumeratePreferredFocusEnvironments + 476
41 UIKitCore                      0x1ad091a10 _enumeratePreferredFocusEnvironments + 476
42 UIKitCore                      0x1ad091a10 _enumeratePreferredFocusEnvironments + 476
43 UIKitCore                      0x1ad09174c -[_UIFocusEnvironmentPreferenceEnumerator enumeratePreferencesForEnvironment:usingBlock:] + 200
44 UIKitCore                      0x1ad091fe8 -[_UIDeepestPreferredEnvironmentSearch deepestPreferredFocusableItemForEnvironment:withRequest:] + 592
45 UIKitCore                      0x1ad0d6484 -[UIFocusUpdateContext _updateDestinationItemIfNeeded] + 232
46 UIKitCore                      0x1ad0d627c -[UIFocusUpdateContext _destinationItemInfo] + 28
47 UIKitCore                      0x1ad0d6158 -[UIFocusUpdateContext nextFocusedItem] + 24
48 UIKitCore                      0x1ad0c5bf8 -[UIFocusSystem updateFocusIfNeeded] + 192
49 UIKitCore                      0x1ad0c5500 __37-[UIFocusSystem _requestFocusUpdate:]_block_invoke + 36
50 UIKitCore                      0x1ada9595c -[_UIAfterCACommitBlock run] + 64
51 UIKitCore                      0x1ad5ff79c _runAfterCACommitDeferredBlocks + 296
52 UIKitCore                      0x1ad5eeb4c _cleanUpAfterCAFlushAndRunDeferredBlocks + 200
53 UIKitCore                      0x1ad620260 _afterCACommitHandler + 76
54 CoreFoundation                 0x1aad2fecc __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 32
55 CoreFoundation                 0x1aad2a5b0 __CFRunLoopDoObservers + 604
56 CoreFoundation                 0x1aad2aaf8 __CFRunLoopRun + 960
57 CoreFoundation                 0x1aad2a200 CFRunLoopRunSpecific + 572
58 GraphicsServices               0x1c0e25598 GSEventRunModal + 160
59 UIKitCore                      0x1ad5f0004 -[UIApplication _run] + 1052
60 UIKitCore                      0x1ad5f55d8 UIApplicationMain + 164
61 MyApp                          0x102d7d654 main + 16 (AppDelegate.swift:16)
62 libdyld.dylib                  0x1aaa09598 start + 4




You’re crashing because you’ve hit an assert within the Swift getter for the IndexPath.section property. AFAICT there’s only one trap in that getter, which fires if the index path has a count other than 2. For example:

Code Block  // This traps because the count is 1:let i1 = IndexPath(indexes: [1])print(i1.section)// This works:let i2 = IndexPath(indexes: [1, 2])print(i2.section)// This traps because the count is 3:let i3 = IndexPath(indexes: [1, 2, 3])print(i3.section)


Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@apple.com"
You should attach the code as well, that's useful to investigate.
Code Block enum ScreenSection : Int {	case firstSection	case secondSection	case thirdSection}extension TableDelegate: UITableViewDataSource {  	func numberOfSections(in tableView: UITableView) -> Int {    		return 3  	}	@available(iOS 11.0, *)  func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> 		UISwipeActionsConfiguration? {         	let section = ScreenSection(rawValue: indexPath.section) <- Here it is crashing	    guard let screenSection = section else {    			return nil    	}			More code...


Thank you for the responses!

Claude31, I just attached some code that shows the numberOfSections and the line where the app is crashing.

eskimo, thank you for that explanation. I went ahead with trying your example on a playground and indeed, I get a EXC-BAD-INSTRUCTION error for the first and third case. But I don't understand why a trap fires if the indexPath has a count other than 2. I'm also curious if this is somehow related to saying that the table view should have 3 sections?

Do you know if there is something wrong about the code itself? Because I'm receiving that indexPath from the trailingSwipeActionsConfigurationForRowAt function as you can see.
Or this is a bug in the language? or how could I fix this? Checking the indexPath.count and saying that this needs to be 2 in order to access the IndexPath.section property?

Thank you in advance

I'm also curious if this is somehow related to saying that the table
view should have 3 sections?

No. In an index path the count value is the number of items in the path. In a table view you should always have a count of 2, representing the section and a row respective.

Because I'm receiving that indexPath from the
trailingSwipeActionsConfigurationForRowAt function as you can see.

Indeed. I don’t have any good theories on that front. My next step would be to run the app under the standard memory debugging tools to see if they flush out a latent memory management bug.

Oh, one more thing: The crash log in your initial post isn’t a full Apple crash report. Do you have one of those for this problem? If so, can you post it?

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@apple.com"
I see. I took this from our crash reporting service. I am attaching a crash log from the user device (this is the same user that was experiencing the crash).
I'm guessing this is a full crash log since this includes the termination signal and reason, etc. Is this correct?

Unfortunately, I haven't had the chance to symbolicate this myself. This is needed or are we more interested in the exception/termination data?



Thanks a lot!!

I'm guessing this is a full crash log since this includes the
termination signal and reason, etc. Is this correct?

Crash reports contain a bunch of useful info. In this case I wanted to do a couple of things, one of which was disassemble the getter to confirm my understanding of the issue:

Code Block  (lldb) disas -s 0x1c3841820 -c 12libswiftUIKit.dylib`merged (extension in UIKit):Foundation.IndexPath.section.getter : Swift.Int:->  0x1c3841820 <+0>:  stp    x20, x19, [sp, #-0x20]!    0x1c3841824 <+4>:  stp    x29, x30, [sp, #0x10]    0x1c3841828 <+8>:  add    x29, sp, #0x10            ; =0x10     0x1c384182c <+12>: mov    x19, x0    0x1c3841830 <+16>: bl     0x1c360819c               ; Foundation.IndexPath.count.getter : Swift.Int    0x1c3841834 <+20>: cmp    x0, #0x2                  ; =0x2     0x1c3841838 <+24>: b.ne   0x1c384184c               ; <+44>    0x1c384183c <+28>: mov    x0, x19    0x1c3841840 <+32>: ldp    x29, x30, [sp, #0x10]    0x1c3841844 <+36>: ldp    x20, x19, [sp], #0x20    0x1c3841848 <+40>: b      0x1c3606acc               ; Foundation.IndexPath.subscript.getter : (Swift.Int) -> Swift.Int    0x1c384184c <+44>: brk    #0x1


Note the brk instruction at +44 which is the immediate cause of the crash. You can only get to that via the branch of +24. That branch is based on comparing the result of the count property (the call at +16) to the the value 2.

Note that at +44 the count is still in register x0. Looking in the crash report you see this:

Code Block  Thread 0 crashed with ARM Thread State (64-bit):    x0: 0x0000000000000000   …


so the count is 0.

So, we’ll still not sure how you got here, but at least we know why you crashed.

Share and Enjoy

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

so the count is 0.
So, we’ll still not sure how you got here, but at least we know why you crashed.

So since the count is 0, this confirms that the app is hitting a IndexPath.section assert.

This is still weird for me why this is happening, but for the users' sake I will put some defensive code checking that the count property is equal to 2 before accessing to the indexPath.section property. Hopefully, this will prevent this crash.

In the case that for some reason this does not work, I will need to go back to this.

Thank you for confirming this and for helping me out!







I also encounter the same crash, is there any hypothesis on why the indexpath is corrupted. Specially because its coming from UITableview @eskimo?

I have this same problem. Accessing the section crashes.

    override func tableView(_ tableView: UITableView, accessoryButtonTappedForRowWith indexPath: IndexPath) {         if indexPath.count != 2 {             print( indexPath.debugDescription )             print( indexPath.description )             print("hi")         } // Outputs // [] // [] // Then crashes         let row = indexPath.section == 0 ? indexPath.row : indexPath.row + 2

Same issue here. The IndexPath is coming directly from UITableView.tableView(_ tableView: UITableView, leadingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration?

Crash: IndexPath.section.getter + 168
 
 
Q