malcommac / SwiftRichString

👩‍🎨 Elegant Attributed String composition in Swift sauce
MIT License
3.13k stars 212 forks source link

I have a crash problem #75

Open motaionx opened 5 years ago

motaionx commented 5 years ago

74EF7E3C-A0B6-45C7-AC03-A0D8EB69DC65

Xcode version : 10.0 (10A255) Swift version: 4.2.0 SwiftRichString version:3.0.0

malcommac commented 5 years ago

In order to reproduce the issue I may need of code. Can you extract your operation outside the project to replicate it?

motaionx commented 5 years ago

@malcommac This problem is not necessarily present, but the probability of occurrence is a bit high. 企业微信截图_61410587-89df-4601-a276-0164f5807506

we use texture(AsyncDisplayKit)

let textNode = ASTextNode().then {
    $0.maximumNumberOfLines = 2
    $0.placeholderColor = .textureDefault
    $0.truncationMode = .byTruncatingTail
}

init(item: HomeServiceItem) {
    super.init()
    automaticallyManagesSubnodes = true
    let name: String
    if item.name.isEmpty {
        name = HomeLocale.allServices.current
    } else {
        name = item.name
    }
    textNode.attributedText = name.set(style: Attributes.textStyle)
    if let u = URL(string: item.indexImage) {
        imageNode.url = u
    }
    discountButtonNode.isHidden = item.discount == 0
    discountButtonNode.setAttributedTitle("-\(item.discount)%".set(style: Attributes.discountTextStyle), for: .normal)
    redNode.isHidden = !(discountButtonNode.isHidden && item.red)
}

struct Attributes {
    static var textStyle = Style {
        $0.font = Font.systemFont(ofSize: 12.autoFont())
        $0.alignment = .center
        $0.lineBreakMode = .byWordWrapping
        $0.color = UIColor(Hex: 0x666666)
    }

    static var discountTextStyle = Style{
        $0.font = Font.boldSystemFont(ofSize: 10)
        $0.alignment = .center
        $0.color = Color.discount
    }
}
motaionx commented 5 years ago

@malcommac

SleepiestAdam commented 4 years ago

Just to confirm - we're getting the same crash (quite rare). We're also using texture, so I presume it's related to the code not being called on the main thread. Would be great to get a fix tho.

SleepiestAdam commented 4 years ago

Just chasing this up @malcommac, as still seeing the same crash / it's the primary cause of crashes in our app at the moment (around a 0.4% rate of occurrence based on crash logs).

SleepiestAdam commented 3 years ago

@malcommac / @motaionx - either of you guys manage to figure out a fix / workaround for this?