jflinter / Dwifft

Swift Diff

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Crash with SingleSectionTableViewDiffCalculator

r00li opened this issue · comments

Hi!
We have started receiving some Crashlytics crash reports in our production app recently. And they all point to some bizarre issue with Dwifft. Now the app has 2k daily active users and the crash happened only 4 times now, so it is not terribly common. None of the QA teams have been able to reproduce it and neither have I. However it happened to three different users.

The crash always happens when setting new rows for the Dwifft SingleSectionTableViewDiffCalculator. We are using the latest version of Dwifft available via Cocoapods.

Basically this is what we get:

Fatal Exception: NSInternalInconsistencyException
attempt to insert row 20 into section 0, but there are only 10 rows in section 0 after the update

Part of the stack trace:

Fatal Exception: NSInternalInconsistencyException
0  CoreFoundation                 0x1becc1ea4 __exceptionPreprocess
1  libobjc.A.dylib                0x1bde91a50 objc_exception_throw
2  CoreFoundation                 0x1bebd7a2c +[_CFXNotificationTokenRegistration keyCallbacks]
3  Foundation                     0x1bf6c61d0 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:]
4  UIKitCore                      0x1ec19e150 -[UITableView _endCellAnimationsWithContext:]
5  UIKitCore                      0x1ec1b70a0 -[UITableView endUpdates]
6  Dwifft                         0x101669340 TableViewDiffCalculator.processChanges(newState:diff:) (Dwifft+UIKit.swift:45)
7  Dwifft                         0x101668cdc specialized AbstractDiffCalculator.sectionedValues.setter (AbstractDiffCalculator.swift:78)
8  Dwifft                         0x10166a308 specialized SingleSectionTableViewDiffCalculator.rows.setter (<compiler-generated>)
9  Dwifft                         0x101669be8 SingleSectionTableViewDiffCalculator.rows.setter (<compiler-generated>)

This is how dwifft is configured:

    private var dataModel: [AppNotification] = []
    private var diffCalculator: SingleSectionTableViewDiffCalculator<AppNotification>?
    ...
    override func viewDidLoad() {
        ...
        diffCalculator = SingleSectionTableViewDiffCalculator<AppNotification>(tableView: self.tableView, initialRows: [], sectionIndex: 0)
        diffCalculator?.insertionAnimation = .top
        diffCalculator?.deletionAnimation = .middle
        ...
    }

The crash happens when we fetch the data from network, prepare and then store it to the dataModel property and then set the self.diffCalculator?.rows = self.dataModel.

Any ideas on what could be the reason for this?