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-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
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





Replies

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 12
libswiftUIKit.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