Crash when last line is smaller than truncate label.
tranngoclinh88 opened this issue · comments
Crash when last line is smaller than truncate label.
NSRange tokenRange = [truncationString.string rangeOfString:attributedTruncationString.string];
NSRange tokenLinkRange = NSMakeRange((NSUInteger)(lastLineRange.location+lastLineRange.length)-tokenRange.length, (NSUInteger)tokenRange.length);
(lastLineRange.location+lastLineRange.length) < tokenRange.length
Then casting to NSUInteger, it return a very big number.
I think I may be seeing a similar crash. I am setting a attributedTruncationToken
and just setting a normal string. This is the stack
*** Terminating app due to uncaught exception 'NSRangeException', reason: 'NSMutableRLEArray objectAtIndex:effectiveRange:: Out of bounds'
*** First throw call stack:
(
0 CoreFoundation 0x00000001148dff45 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x0000000114359deb objc_exception_throw + 48
2 CoreFoundation 0x00000001148dfe7d +[NSException raise:format:] + 205
3 Foundation 0x000000010ffe568b -[NSRLEArray objectAtIndex:effectiveRange:] + 142
4 Foundation 0x0000000110019bb1 -[NSMutableAttributedString addAttributes:range:] + 181
5 App 0x000000010db01976 -[TTTAttributedLabel addLinks:] + 742
6 App 0x000000010db020b5 -[TTTAttributedLabel addLinksWithTextCheckingResults:attributes:] + 1045
7 App 0x000000010db01bf8 -[TTTAttributedLabel addLinkWithTextCheckingResult:attributes:] + 184
8 App 0x000000010db021e2 -[TTTAttributedLabel addLinkWithTextCheckingResult:] + 130
9 App 0x000000010db022b9 -[TTTAttributedLabel addLinkToURL:withRange:] + 137
10 App 0x000000010db04cb3 -[TTTAttributedLabel drawFramesetter:attributedString:textRange:inRect:context:] + 3315
11 App 0x000000010db0a0b5 -[TTTAttributedLabel drawTextInRect:] + 3285
12 UIKit 0x0000000110fb33e5 -[UILabel drawRect:] + 100
13 UIKit 0x0000000110df889e -[UIView(CALayerDelegate) drawLayer:inContext:] + 495
14 QuartzCore 0x0000000110a8c183 -[CALayer drawInContext:] + 257
15 QuartzCore 0x000000011098133d CABackingStoreUpdate_ + 2688
16 QuartzCore 0x0000000110a8c002 ___ZN2CA5Layer8display_Ev_block_invoke + 59
17 QuartzCore 0x0000000110a8be80 _ZN2CA5Layer8display_Ev + 1460
18 QuartzCore 0x0000000110a80c69 _ZN2CA5Layer17display_if_neededEPNS_11TransactionE + 293
19 QuartzCore 0x0000000110a80cf9 _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 35
20 QuartzCore 0x0000000110a75475 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 277
21 QuartzCore 0x0000000110aa2c0a _ZN2CA11Transaction6commitEv + 486
22 QuartzCore 0x0000000110aa337c _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 92
23 CoreFoundation 0x000000011480b947 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
24 CoreFoundation 0x000000011480b8b7 __CFRunLoopDoObservers + 391
25 CoreFoundation 0x000000011480150b __CFRunLoopRun + 1147
26 CoreFoundation 0x0000000114800e08 CFRunLoopRunSpecific + 488
27 GraphicsServices 0x000000011666aad2 GSEventRunModal + 161
28 UIKit 0x0000000110d4430d UIApplicationMain + 171
29 App 0x000000010d19062f main + 111
30 libdyld.dylib 0x00000001153b892d start + 1
31 ??? 0x0000000000000003 0x0 + 3
)
libc++abi.dylib: terminating with uncaught exception of type NSException```
Also worth noting that if I don't set NSLinkAttributeName
as an attribute of the truncation token the crash does not happen. But if I don't do that how can I use the truncation token as a link..?
Any updates for this?
I've experienced a similar issue recently and it's an issue when the line has a length less than the truncation tokens length.
@joshuafeldman Removing NSLinkAttributeName
stops the crash but kills the link functionality.
I've created a write up and included the demo project here on my Github
On a side note, Is this project still maintained?
Hello guys,
How can I fix this? Thanks you