chrisdhaan / CDMarkdownKit

An extensive Swift framework providing simple and customizable markdown parsing.
MIT License
254 stars 66 forks source link

Crash in CDFont+CDMarkdownKit.swift, line 57. Unexpectedly found nil when unwrapping optional value. #34

Open mathist opened 3 years ago

mathist commented 3 years ago

What did you do?

                        if let m = chat.message
                           , let font = UIFont(name: "Lato-Regular", size: 20.0)
                        {   
                            let markdownParser = CDMarkdownParser(font: font)
                        }

What did you expect to happen?

No crash

What happened instead?

Crash in CDFont+CDMarkdownKit.swift, line 57. Unexpectedly found nil when unwrapping optional value.

CDMarkdownKit Environment

CDMarkdownKit v2.1.1 xcode 12.5.1 swift v5.0 iOS Simulator macOS 11.4

This is the CDMarkdownKit code that crashed, it crashed on the force unwrap of "descriptor" variable.

private func withTraits(_ traits: CDFontDescriptorSymbolicTraits...) -> CDFont {
    let descriptor = fontDescriptor.withSymbolicTraits(CDFontDescriptorSymbolicTraits(traits))
    return CDFont(descriptor: descriptor!,
                  size: self.pointSize)
}
chrisdhaan commented 2 years ago

Thanks for pointing this out @mathist . I'll take a look

ARGAMX commented 3 months ago

Still crashing on this line.

let parser = CDMarkdownParser(font: textFont, backgroundColor: UIColor.clear)