Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inconsistent state/crash when removing rows from sections with removeAll(where:) #2048

Closed
bvirlet opened this issue Jun 8, 2020 · 4 comments · Fixed by #2141
Closed

Inconsistent state/crash when removing rows from sections with removeAll(where:) #2048

bvirlet opened this issue Jun 8, 2020 · 4 comments · Fixed by #2141

Comments

@bvirlet
Copy link

bvirlet commented Jun 8, 2020

  • Environment: Eureka: 62484db, Xcode 11.5 and iOS 13.4.1

Test case:

@testable import Eureka
import Foundation
import XCTest

class SectionTests: XCTestCase {
    func testDeletingRows() {
        let form = Form()
        var section = Section("section_01")
        form.append(section)
        
        section.append(NameRow(tag: "row_01"))
        section.append(NameRow(tag: "row_02"))
        
        section.removeAll(where: { row in row.tag == "row_01" }) // <-- Thread 1: Assertion failed: Duplicate tag row_02
        XCTAssertNotNil(form.rowBy(tag: "row_02"))
    }
}

Backtrace:

#0 0x00000001100c4330 in swift_runtime_on_report ()
#1 0x000000011013e0b3 in swift_stdlib_reportFatalErrorInFile ()
#2 0x000000010fe0073e in closure #1 in closure #1 in closure #1 in assertionFailure(:
:file:line🎏) ()
#3 0x000000010fe00347 in closure #1 in closure #1 in assertionFailure(:
:file:line🎏) ()
#4 0x000000010fe00927 in specialized String.withUTF8(:) ()
#5 0x000000010fdfef4a in assertionFailure(:
:file:line🎏) ()
#6 0x000000010f94a7a7 in BaseRow.wasAddedTo(section:) at /Users/bruno/Downloads/Eureka/Source/Core/BaseRow.swift:198
#7 0x000000010f9ae878 in Section.subscript.setter at /Users/bruno/Downloads/Eureka/Source/Core/Section.swift:267
#8 0x000000010f9afa56 in protocol witness for MutableCollection.subscript.setter in conformance Section ()
#9 0x000000010fdd9364 in MutableCollection.swapAt(::) ()
#10 0x000000010f9afce2 in protocol witness for MutableCollection.swapAt(::) in conformance Section ()
#11 0x000000010fe183e0 in MutableCollection._halfStablePartition(isSuffixElement:) ()
#12 0x000000010fded891 in RangeReplaceableCollection<>.removeAll(where:) ()
#13 0x000000010f916ad5 in SectionTests.testDeletingRows() at /Users/bruno/Downloads/Eureka/Tests/SectionTests.swift:21
#14 0x000000010f916d7b in @objc SectionTests.testDeletingRows() ()

Log:

Assertion failed: Duplicate tag row_02: file Eureka/Source/Core/BaseRow.swift, line 198
2020-06-08 10:16:09.489302+0200 xctest[4711:94968] Assertion failed: Duplicate tag row_02: file Eureka/Source/Core/BaseRow.swift, line 198
@mats-claassen
Copy link
Member

Thanks for sharing with a test case. I can reproduce this. Seems that something changed in the internal implementation of this method?
Weird also that remove(where:) calls the subscript to replace elements without removing them first.

A possible fix would be to reimplement this method. Any other suggestion?

@chickendiver
Copy link

Bump. This is causing crashes for me as well.

@chickendiver
Copy link

Possibly related: #1643

@navyseai
Copy link

navyseai commented Feb 12, 2021

im getting a crash here on removeAll => sectionsHaveBeenRemoved ... but it seems to happen randomly

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

Successfully merging a pull request may close this issue.

4 participants