optonaut / ActiveLabel.swift

UILabel drop-in replacement supporting Hashtags (#), Mentions (@) and URLs (http://) written in Swift
MIT License
4.47k stars 686 forks source link

NSRangeException #14

Closed gloparco closed 8 years ago

gloparco commented 8 years ago

Hi Johannes, thanks for ActiveLabel - nice work!

I notice that when using ActiveLabel in a CollectionView and scrolling up or down, I sometimes get the following error:

*\ Terminating app due to uncaught exception 'NSRangeException', reason: 'NSMutableRLEArray objectAtIndex:effectiveRange:: Out of bounds'

This has also been documented in another UILabel github lib (Obj-C), here:

https://github.com/SebastienThiebaud/STTweetLabel/issues/55

The bug is hard to reproduce, but it has happened multiple times. It doesn't appear to be associated with the speed of scrolling or anything else I can reproduce, but as I mentioned, it has happened multiple times now, and it does seem related to ActiveLabel. Sorry I can't be of more help.

gloparco commented 8 years ago

Just to add to it, here is a long discussion on the topic (from a site that I had never heard of before):

http://youranswers.info/question/view/en/YUhSMGNEb3ZMM04wWVdOcmIzWmxjbVpzYjNjdVkyOXRMM0YxWlhOMGFXOXVjeTh4T0RrMk1qYzBNaTkxYVhSbGVIUjJhV1YzTFd4cGJtc3RaR1YwWldOMGFXOXVMV2x1TFdsdmN5MDM=

I'm not sure if this can be prevented by your code, but it might be worth looking into. It seems to have something to do with AttributedString, but it does not appear to be certain.

schickling commented 8 years ago

Hi @gloparco! Thanks for reporting this. We're using ActiveLabel just as part of a UITableView, so we haven't had this issue so far and unfortunately don't have the capacity at the moment to look into it in depth.

However we'd be more than happy to merge a PR which resolves this issue.

ammerzon commented 8 years ago

@gloparco I am using ActiveLabel in an UITableViewCell but every time i set a text containing an @ or # I get a NSRangeException.

polqf commented 8 years ago

Hi @byAmmerix, in what SDK and iOS version have you noticed it?

ammerzon commented 8 years ago

I am using: Cocoapods: pod 'ActiveLabel', '~> 0.4' iOS version/SDK: 9.2

It is the same bug as @JaviSoto already mentioned in #40. The crash occurs at: mutAttrString.setAttributes(attributes, range: element.range)

alexbredy commented 8 years ago

+1 happens to me every time i close and reopen a given tableview repeatedly.

polqf commented 8 years ago

@alexbredy what dependency manager are you using? iOS and SDK version?

alexbredy commented 8 years ago

Hi @poolqf

Using Cocoapods with iOS version 9.2.1 and SDK 9.2 (Xcode 7.2.1)

Update regarding the issue I'm having: The crash does not occur if I'm not adding cells upon opening the tableview. Somehow when I keep adding rows with the same url it crashes after 4-5 times closing and reopening the tableview.

The crash does not happen if the cells are unaltered.

adergaard commented 8 years ago

The problem is most likely possibly due to row 190 in ActiveLabel.swift:

dispatch_async

Quickfix: Comment out that row (and consequently the closing } on row 194) and let the commands execute on the main thread instead and the crash is no more.

Be very careful trying to do stuff outside the main thread. It's therefore also well worth noting the dispatch_after call made in the onTouch method.

polqf commented 8 years ago

I've removed the dispatch_async in #47 I am now going to create a new release. Closing this issue.

Feel free to reopen it if it happens again

cc/ @byAmmerix , @alexbredy , @JaviSoto