Skip to content
This repository has been archived by the owner on Apr 15, 2020. It is now read-only.

Exclusive Access to Memory exception in TableEditingController / commitEditing closure #113

Closed
jessesquires opened this issue Jul 9, 2018 · 3 comments
Assignees

Comments

@jessesquires
Copy link
Owner

Per: #92 (comment)

It appears that as of Swift 4, passing the dataSource as inout causing a simultaneous memory access crash when calling tableView.deleteRows(at: [indexPath], with: .automatic) from the Table commitEditing callback, even in the example app.

let editingController: TableEditingController<DataSource<CellViewModel>> = TableEditingController(
    canEditRow: { (item, tableView, indexPath) -> Bool in
        return true
},
    commitEditing: { (dataSource: inout DataSource, tableView, editingStyle, indexPath) in
        if editingStyle == .delete {
            if dataSource.remove(at: indexPath) != nil {
                tableView.deleteRows(at: [indexPath], with: .automatic)
            }
        }
})

Here's the Swift proposal.

Selecting No Enforcement for Exclusive Access to Memory from Swift Compiler - Code Generation in the project's build settings resolves the crash, but seems like more of a work-around rather than an actual fix.

@u10int
Copy link

u10int commented Sep 30, 2018

Any update on this issue? Looks like the build setting work-around is no longer working and resulting in crashes in-app. I just removed the inout flag on the DataSource parameter in DataSourceProvider and the accompanying CommitEditingConfig typealias which appears to be working without issues for the time being.

@jessesquires jessesquires added this to the 8.1.0 milestone Mar 6, 2019
@jessesquires jessesquires removed this from the 8.1.0 milestone Sep 30, 2019
@jessesquires
Copy link
Owner Author

Well...

Much to my disappointment, I'm not sure how we can fix this. Seems we've "designed ourselves into a corner."

Notes on my attempt to fix:

In DataSourceProvider.swift:

dataSource.tableCommitEditingStyleForRow = { [unowned self] tableView, editingStyle, indexPath in
    var copy = self.dataSource
    self.tableEditingController?.commitEditing(&copy, tableView, editingStyle, indexPath)
    self.dataSource = copy
}

This fixes the memory exclusivity error. (good)

However, it results in a table view inconsistency exception (bad). Not surprising. The copy leaves the data source in an inconsistent state.

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 
'Invalid update: invalid number of rows in section 0. 
The number of rows contained in an existing section after the update (3) 
must be equal to the number of rows contained in that section before the update (3), 
plus or minus the number of rows inserted or deleted from that section (0 inserted, 1 deleted) 
and plus or minus the number of rows moved into or out of that section (0 moved in, 0 moved out).'

@jessesquires
Copy link
Owner Author

This library is now deprecated.

See announcement:
https://www.jessesquires.com/blog/2020/04/14/deprecating-jsqdatasourceskit/

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants