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

Crash reported parsing markdown #69

Closed
tsfischer opened this issue Feb 16, 2018 · 7 comments
Closed

Crash reported parsing markdown #69

tsfischer opened this issue Feb 16, 2018 · 7 comments
Assignees
Milestone

Comments

@tsfischer
Copy link

We have had a significant number of crashes reported from the field via Crashlytics. The crash is:
Fatal Exception: NSInvalidArgumentException
*** -[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from objects[0]

and the call stack looks like:
Fatal Exception: NSInvalidArgumentException
0 CoreFoundation 0x7fffc5cb72b3 (Missing)
1 libobjc.A.dylib 0x7fffdaace48d (Missing)
2 CoreFoundation 0x7fffc5bb43f0 (Missing)
3 CoreFoundation 0x7fffc5bb425b (Missing)
4 TSMarkdownParser 0x10a1707ad (Missing)
5 TSMarkdownParser 0x10a170991 (Missing)
6 Self Service 0x109af1fde specialized SSHistoryContentCellView.(content.didset).(closure #1) (SSHistoryContentCellView.swift:37)

Here is the SSHistoryContentCellView code in question:

              let attrDescription = TSMarkdownParser.standard().attributedString(fromMarkdown: self.content.jssDescription ?? "", attributes: [NSAttributedStringKey.foregroundColor.rawValue : NSColor.descriptionTextColor()])
                self.descriptionLabel.isHidden = attrDescription.length == 0
                self.descriptionLabel.textStorage?.setAttributedString(attrDescription)
                self.descriptionHeightConstraint.constant = self.self.descriptionLabel.heightForString()

Looking at the pod code and our own code, the only usage of NSDictionary is for the attributes. But I am passing in a constant for the attributes dictionary, so that should never go null. I am at a loss of what might be causing this, and I am unable to reproduce it in-house.

@Coeur
Copy link
Collaborator

Coeur commented Mar 5, 2018

@tsfischer Can you confirm that:

  • it's macOS? (and not iOS/tvOS)
  • it's TSMarkdownParser 2.1.3?
  • it's Swift 4.0/Xcode 9.2?

Can you give more details about the value of [NSAttributedStringKey.foregroundColor.rawValue : NSColor.descriptionTextColor()]?

@tsfischer
Copy link
Author

Thanks much for your response. Since writing this post, I discovered that our customer was deleting all fonts from the /Library/Fonts folder and that was causing this crash. They are a publishing house and want to clear out this folder for copyright reasons.

For the short term, we told them to put fonts back until the crash goes away... but it would be nice if TSMarkdownParser wouldn't crash if it encounters a missing font.

As a note, they aren't actually using markdown... so only normal strings (no markdown tags) are being used and no additional fonts requested.

@Coeur
Copy link
Collaborator

Coeur commented Mar 5, 2018

I'll be working on TSMarkdownParser today, so it's your chance. But I need a way to reproduce the issue. You're mentioning fonts, but the code you gave is about foregroundColor only. Also can you specify the macOS Deployment Target? Is it 10.9, 10.10, 10.11, 10.12 or 10.13?

@Coeur
Copy link
Collaborator

Coeur commented Mar 5, 2018

I tried this:

let attrDescription = TSMarkdownParser.standard()
                        .attributedString(fromMarkdown: "SSHistoryContentCellView text",
                          attributes: [NSAttributedStringKey.foregroundColor.rawValue : NSColor.blue])
print(attrDescription)

And I got a correct print with no crash:

SSHistoryContentCellView text{
NSColor = "sRGB IEC61966-2.1 colorspace 0 0 1 1";
}

But we have font usage when dealing with:

  • headerAttributes (i.e. "# hello")
  • quoteAttributes (i.e. "> hello")
  • monospaceAttributes (i.e. "hello")
  • strongAttributes (i.e. "hello")
  • emphasisAttributes (i.e. "hello")

So I tried:

let attrDescription = TSMarkdownParser.standard()
                        .attributedString(fromMarkdown: "# hello\n> hello\n`hello` __hello__ _hello_",
                          attributes: [NSAttributedStringKey.foregroundColor.rawValue : NSColor.blue])
print(attrDescription)

But I still didn't get any crash on macOS High Sierra (10.13.3). Please help to reproduce the issue, @tsfischer. And if you're removing a font from the app, then you should overwrite the default settings from the app that were using this font:

    TSMarkdownParser.standard().headerAttributes = [[:]]// or whatever you want
    TSMarkdownParser.standard().quoteAttributes = [[:]]// or whatever you want
    TSMarkdownParser.standard().monospaceAttributes = [:]// or whatever you want
    TSMarkdownParser.standard().strongAttributes = [:]// or whatever you want
    TSMarkdownParser.standard().emphasisAttributes = [:]// or whatever you want

@Coeur
Copy link
Collaborator

Coeur commented Mar 5, 2018

Oh, OK, I start to understand. If you remove HelveticaNeue-Italic from the system, then this simple call will create a crash:

let parser = TSMarkdownParser.standard()

And this will be caused by:

_quoteAttributes = @[@{NSFontAttributeName: [UIFont fontWithName:@"HelveticaNeue-Italic" size:defaultSize]}];

I'll workaround this.

Coeur added a commit that referenced this issue Mar 5, 2018
@Coeur Coeur self-assigned this Mar 5, 2018
@Coeur Coeur added this to the 2.1.4 milestone Mar 5, 2018
@Coeur Coeur added the bug label Mar 5, 2018
@Coeur
Copy link
Collaborator

Coeur commented Mar 5, 2018

Fixed in 2.1.4

@Coeur Coeur closed this as completed Mar 5, 2018
@Coeur Coeur added the duplicate label Mar 5, 2018
@Coeur
Copy link
Collaborator

Coeur commented Mar 5, 2018

Actually a duplicate of #58

Coeur added a commit that referenced this issue Mar 6, 2018
* master:
  fix macOS example
  updating to 2.1.4
  #69: avoiding crash if font is missing
  project clang warning update
  Add Syntax Highlighting
  Add spacing to headers
  updating to 2.1.3
  simplification of the enumeration
  # Fix for Issue #62 # Ensured that autodetect linking does not overlap existing links; which happens in case the link text contains text that could be auto detected as links.
  adding myself as author
  updating to 2.1.2
  add ercentEscapesUsingEncoding

# Conflicts:
#	CHANGELOG.md
#	README.md
#	TSMarkdownParser.podspec
#	TSMarkdownParser.xcodeproj/project.pbxproj
#	TSMarkdownParser/TSMarkdownParser.m
#	TSMarkdownParserExample OSX/ViewController.m
#	TSMarkdownParserTests/TSMarkdownParserTests.m
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants