Open brod-ie opened 6 years ago
ASTextNodeDelegate's method textNode:longPressedLinkAttribute:value:atPoint:textRange will crash when no _highlightedLinkAttributeName or _highlightedLinkAttributeValue is set.
textNode:longPressedLinkAttribute:value:atPoint:textRange
_highlightedLinkAttributeName
_highlightedLinkAttributeValue
I use this method to detect long pressing of my cell's text. Not all of my NSAttributedString has the .link attribute set, I imagine this could be causing the crash.
.link
Stack trace:
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x0) frame #0: 0x00000001137762cf libswiftCore.dylib`swift_getObjectType + 47 frame #1: 0x000000010a016d17 muzmatch`@objc ASChatCell.textNode(_:longPressedLinkAttribute:value:at:textRange:) at ASChatCell.swift:0 * frame #2: 0x000000010b4995d6 AsyncDisplayKit`::-[ASTextNode _handleLongPress:](self=0x00007ffea0080a00, _cmd="_handleLongPress:", longPressRecognizer=0x00007ffe9bc38f10) at ASTextNode.mm:1062 frame #3: 0x000000010de9b41b UIKit`-[UIGestureRecognizerTarget _sendActionWithGestureRecognizer:] + 57 frame #4: 0x000000010dea41f0 UIKit`_UIGestureRecognizerSendTargetActions + 109 frame #5: 0x000000010dea1a38 UIKit`_UIGestureRecognizerSendActions + 307 frame #6: 0x000000010dea0c8c UIKit`-[UIGestureRecognizer _updateGestureWithEvent:buttonEvent:] + 859 frame #7: 0x000000010de85cf0 UIKit`_UIGestureEnvironmentUpdate + 1329 frame #8: 0x0000000112359607 CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23 frame #9: 0x000000011235955e CoreFoundation`__CFRunLoopDoObservers + 430 frame #10: 0x000000011233db81 CoreFoundation`__CFRunLoopRun + 1537 frame #11: 0x000000011233d30b CoreFoundation`CFRunLoopRunSpecific + 635 frame #12: 0x00000001160bda73 GraphicsServices`GSEventRunModal + 62 frame #13: 0x000000010d8a30b7 UIKit`UIApplicationMain + 159 frame #14: 0x0000000109c2cea7 muzmatch`main at AppDelegate.swift:31 frame #15: 0x00000001140dc955 libdyld.dylib`start + 1
As I don't want to set this when a link isn't specified within a text range, I've bodged the delegate to accommodate nil values:
if (_highlightedLinkAttributeName == nil) { _highlightedLinkAttributeName = @""; } if (_highlightedLinkAttributeValue == nil) { _highlightedLinkAttributeValue = @""; }
You can see these changes in this PR.
Plot twist, you can also fix this method by setting the delegates parameters to incorrectly (according to the header I imagine) be optional:
ASTextNodeDelegate's method
textNode:longPressedLinkAttribute:value:atPoint:textRange
will crash when no_highlightedLinkAttributeName
or_highlightedLinkAttributeValue
is set.I use this method to detect long pressing of my cell's text. Not all of my NSAttributedString has the
.link
attribute set, I imagine this could be causing the crash.Stack trace:
As I don't want to set this when a link isn't specified within a text range, I've bodged the delegate to accommodate nil values:
You can see these changes in this PR.