Error in iOS 14.5 and 14.6 with code running fine in 14.2... how to BEGIN to solve this?

481 views Asked by At

Summary:

App runs fine with iOS 14.2; crashes consistently with an unhelpful error message, both simulator and device, with iOS 14.5 and 14.6. I located the code whose presence/absence produces or removes the error, but it's an essential part of the user interface. Where does one begin to start solving such a situation?

Details:

Big app, all in Swift, using SwiftUI for nearly all the UI, lots of screen elements, core data, some multi-threading. In the simulator using iOS 14.2, the app runs fine (as it did on my iPad, until I updated the iOS). I recently updated my iPad to iOS 14.6, and when I run the app on the device, I get the crash I'll describe below. Same exact code in the 14.2 simulator, runs fine, no crash. When I run the code on an iOS 14.5 simulator (no sim available for 14.6 yet), same crash in that simulator as on the device.

Narrowing down where the crash happens, I find it's in code that looks like this:

    var body: some View {
        GeometryReader { geometry in
            HStack(spacing: 0){                
                LeftMainColumn()
                CenterMainColumn()
                RightMainColumn()                
            }            
        }
    } 

Each column looks about like this:

struct LeftMainColumn: View {
    func someData() -> [String] {
        return ["a","b","c"]      // different data in each column
    }
    var body: some View {
        GeometryReader { geom in
            ZStack {
                Rectangle()
                    .fill(Color.red)
                List{
                    ForEach(someData(), id: \.self) { dat in
                        Text("data: \(dat)")
                            .listRowBackground(Color.red)
                    }
                }
            }       // closes ZStack
        }       // closes GeometryReader
    }       // closes var body
}       // closes struct

The other two columns are basically the same, with different data.

Compared to the actual project, this code is highly simplified, and I include it to communicate a sense of where the crash is occurring. With this simple code, the crash doesn't occur. (There is lots more on the screen in the real app; perhaps that stresses something enough to produce the problem.)

When I comment out any one of the columns, the remaining two display fine on the 14.5 sim and 14.6 device. When I have all 3 columns, the 14.5 sim and the 14.6 device crash, with the following report (the 14.2 sim runs fine with all 3 columns):

2021-06-24 19:58:02.989478-0500 AppName[40446:97339181] *** Assertion failure in -[_TtC7SwiftUIP33_BFB370BA5F1BADDC9D83021565761A4925UpdateCoalescingTableView _endCellAnimationsWithContext:], UITableView.m:2193
2021-06-24 19:58:03.020894-0500 AppName[40446:97339181] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'attempt to insert section 0 but there are only 0 sections after the update'
*** First throw call stack:
(
    0   CoreFoundation                      0x000000010daa7fba __exceptionPreprocess + 242
    1   libobjc.A.dylib                     0x000000010d0aaff5 objc_exception_throw + 48
    2   CoreFoundation                      0x000000010daa7de3 +[NSException raise:format:] + 0
    3   Foundation                          0x000000010cb478e7 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 191
    4   UIKitCore                           0x000000012bf82920 -[UITableView _endCellAnimationsWithContext:] + 9394
    5   UIKitCore                           0x000000012bf9dff7 -[UITableView endUpdatesWithContext:] + 116
    6   UIKitCore                           0x000000012bf9e1c9 -[UITableView _performBatchUpdates:withContext:completion:] + 253
    7   UIKitCore                           0x000000012bf9e2af -[UITableView performBatchUpdates:completion:] + 97
    8   SwiftUI                             0x000000010f37a801 $s7SwiftUI25UpdateCoalescingTableView33_BFB370BA5F1BADDC9D83021565761A49LLC19performBatchUpdates_10completionyyycSg_ySbcSgtF + 378
    9   SwiftUI                             0x000000010f37a8da $s7SwiftUI25UpdateCoalescingTableView33_BFB370BA5F1BADDC9D83021565761A49LLC19performBatchUpdates_10completionyyycSg_ySbcSgtFTo + 175
    10  SwiftUI                             0x000000010f37d31d $s7SwiftUI19ListCoreCoordinator33_BFB370BA5F1BADDC9D83021565761A49LLC17updateUITableView_2to11transactionySo0mN0C_xAA11TransactionVtF14performUpdatesL_yyAA0cD10DataSourceRzAA16SelectionManagerR_0V5ValueQy_AORtzr0_lF + 1594
    11  SwiftUI                             0x000000010f723652 $sIg_Ieg_TR + 12
    12  SwiftUI                             0x000000010f723668 $sIeg_IyB_TR + 14
    13  UIKitCore                           0x000000012c2cfbb9 +[UIView(Animation) performWithoutAnimation:] + 84
    14  SwiftUI                             0x000000010f37dc6f $s7SwiftUI19ListCoreCoordinator33_BFB370BA5F1BADDC9D83021565761A49LLC17updateUITableView_2to11transactionySo0mN0C_xAA11TransactionVtFyycfU_ + 467
    15  SwiftUI                             0x000000010f266eb7 $sIeg_ytIegr_TR + 12
    16  SwiftUI                             0x000000010f3851cf $sIeg_ytIegr_TRTA + 17
    17  SwiftUI                             0x000000010f38899f $sIeg_ytIegr_TRTA.42 + 9
    18  SwiftUI                             0x000000010f250ec4 $s7SwiftUI6UpdateO3endyyFZ + 433
    19  SwiftUI                             0x000000010f0a83fd $sSo9NSRunLoopC7SwiftUIE14flushObserversyyFZ + 148
    20  SwiftUI                             0x000000010f0a8367 $sSo9NSRunLoopC7SwiftUIE11addObserveryyyycFZySo05CFRunbF3RefaSg_So0gB8ActivityVSvSgtcfU_yyXEfU_ + 9
    21  SwiftUI                             0x000000010f0a35fe $ss5Error_pIgzo_ytsAA_pIegrzo_TR95$sSo9NSRunLoopC7SwiftUIE11addObserveryyyycFZySo05CFRunbF3RefaSg_So0gB8ActivityVSvSgtcfU_yyXEfU_Tf3npf_n + 14
    22  libswiftObjectiveC.dylib            0x000000011445e03e $s10ObjectiveC15autoreleasepool8invokingxxyKXE_tKlF + 46
    23  SwiftUI                             0x000000010f0a8356 $sSo9NSRunLoopC7SwiftUIE11addObserveryyyycFZySo05CFRunbF3RefaSg_So0gB8ActivityVSvSgtcfU_ + 35
    24  SwiftUI                             0x000000010f0a8459 $sSo9NSRunLoopC7SwiftUIE11addObserveryyyycFZySo05CFRunbF3RefaSg_So0gB8ActivityVSvSgtcfU_To + 43
    25  CoreFoundation                      0x000000010da14d31 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
    26  CoreFoundation                      0x000000010da0f542 __CFRunLoopDoObservers + 541
    27  CoreFoundation                      0x000000010da0faf5 __CFRunLoopRun + 1129
    28  CoreFoundation                      0x000000010da0f1a7 CFRunLoopRunSpecific + 567
    29  GraphicsServices                    0x00000001194d2d85 GSEventRunModal + 139
    30  UIKitCore                           0x000000012bd854df -[UIApplication _run] + 912
    31  UIKitCore                           0x000000012bd8a39c UIApplicationMain + 101
    32  PlayingWithSwiftUI_10_OverallFlow   0x000000010a18ac6b main + 75
    33  libdyld.dylib                       0x0000000115fa0bbd start + 1
    34  ???                                 0x0000000000000001 0x0 + 1
)
libc++abi: terminating with uncaught exception of type NSException
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'attempt to insert section 0 but there are only 0 sections after the update'
terminating with uncaught exception of type NSException
CoreSimulator 757.5 - Device: 14.5 iPadAir3rdGen (7EB4A57C-0A14-4C84-8740-943D694B877A) - Runtime: iOS 14.5 (18E182) - DeviceType: iPad Air (3rd generation)

I can also get rid of the crash by replacing the ForEach statement with a series of Text("x") statements, but the whole point of the app is that it displays actual data, not x x x.

Okay, so I've identified where the crash is happening in the 14.5 / 14.6 sim/device, but I don't have any idea how to go about solving the crash. The app absolutely has to have all 3 columns present, so "just delete one column," while it absolutely avoids the error, isn't a solution.

Other than "hope they fix this in iOS 15," where does one start to work on fixing an app that ran (still runs) fine in iOS 14.2 but dies in the later iOS versions?

1

There are 1 answers

0
Danilo Campos On

You mentioned Core Data.

I just found a fix for this in my project, which was suffering from the same problem:

  • Newly crashing as of 14.5
  • Unhelpful stack trace
  • Log output complaining attempt to insert section 0 but there are only 0 sections after the update

For a file of this structure:

struct CrashingView: View {
    
    @FetchRequest var listContent: FetchedResults<Entity>

    var body: some View {
        List {
            ForEach(listContent, id:\.self) {
                 Cell($0)
        }
    }

}

the fix is to check that your fetch content has a count greater than 0:

struct CrashingView: View {
    
    @FetchRequest var listContent: FetchedResults<Entity>

    var body: some View {

        if listContent.count > 0 {
            List {
                ForEach(listContent, id:\.self) {
                     Cell($0)
                 }
            }
        } else {
          EmptyView()
        }
    }

}

A little stupid, yes, but an easy enough fix. Hope it helps in your case.