Skip to content
This repository has been archived by the owner on Feb 2, 2023. It is now read-only.

[ASTextNode] ASTextKitAttributes.h line 28 crash when setting an attributed string. #1594

Closed
klivin opened this issue Apr 26, 2016 · 8 comments

Comments

@klivin
Copy link

klivin commented Apr 26, 2016

Hi, I am getting a frequent crash in our production app when an attributed string is set on an ASText Node. Are there any thoughts on what I could check on the attributed string to make sure this is not happening? I have a hunch that there is some unhandled Hebrew text being set in the attributed string, but I have not been able to reproduce the issue in development. Below are the stack traces:

Stack trace:

Crashed: org.AsyncDisplayKit.ASDisplayLayer.displayQueue
0 libobjc.A.dylib 0x1995b80b0 objc_retain + 16
1 libobjc.A.dylib 0x1995b8128 objc_storeStrong + 44
2 jswipe 0x1002fe688 -ASTextKitRenderer initWithTextKitAttributes:constrainedSize:
3 jswipe 0x10030208c -ASTextNode _rendererWithBounds:
4 jswipe 0x100302da0 -ASTextNode drawRect:withParameters:isCancelled:isRasterizing:
5 jswipe 0x1002bb958 __90-[ASDisplayNode(AsyncDisplay) _displayBlockWithAsynchronous:isCancelledBlock:rasterizing:]_block_invoke.70 (ASDisplayNode+AsyncDisplay.mm:286)
6 jswipe 0x10030c39c __71-[_ASAsyncTransaction addOperationWithBlock:priority:queue:completion:]_block_invoke (_ASAsyncTransaction.mm:405)
7 jswipe 0x10030b70c ___ZN23ASAsyncTransactionQueue9GroupImpl8scheduleElPU28objcproto17OS_dispatch_queue8NSObjectU13block_pointerFvvE_block_invoke (_ASAsyncTransaction.mm:236)
8 libdispatch.dylib 0x199db16e8 _dispatch_call_block_and_release + 24
9 libdispatch.dylib 0x199db16a8 _dispatch_client_callout + 16
10 libdispatch.dylib 0x199dbbf7c _dispatch_async_redirect_invoke + 1920
11 libdispatch.dylib 0x199db16a8 _dispatch_client_callout + 16
12 libdispatch.dylib 0x199dbfb40 _dispatch_root_queue_drain + 2140
13 libdispatch.dylib 0x199dbf2dc _dispatch_worker_thread3 + 112
14 libsystem_pthread.dylib 0x199fc5470 _pthread_wqthread + 1092
15 libsystem_pthread.dylib 0x199fc5020 start_wqthread + 4

Here's the main thread stack leading to crash:
com.apple.main-thread
0 libsystem_kernel.dylib 0x199efef90 psynch_mutexwait + 8
1 libsystem_pthread.dylib 0x199fca39c _pthread_mutex_lock_wait + 96
2 jswipe 0x1002a218c ASDN::Mutex::lock() (ASThread.h:124)
3 jswipe 0x1003022d4 -ASTextNode _invalidateRenderer
4 jswipe 0x100302b0c -ASTextNode setAttributedString:
5 jswipe 0x1000c9af0 specialized ContentNode.primaryAttributedString.setter (ContentNode.swift:17)
6 jswipe 0x1000c8818 ContentNode.primaryAttributedString.setter (ContentNode.swift)
7 jswipe 0x10010da30 specialized CircleProfileImageNode.setContentText(String, secondaryText : String?) -> () (SwipeCellSubviews.swift:46)
8 jswipe 0x10010a9a0 CircleProfileImageNode.setContentText(String, secondaryText : String?) -> () (SwipeCellSubviews.swift:29)
9 jswipe 0x100134208 SwipeCell.(refreshCellData() -> ()).(closure #1) (SwipeCell.swift:173)
10 jswipe 0x100140d50 partial apply for thunk (SMLUser.swift)
11 libdispatch.dylib 0x199db16e8 _dispatch_call_block_and_release + 24
12 libdispatch.dylib 0x199db16a8 _dispatch_client_callout + 16
13 libdispatch.dylib 0x199db6db0 _dispatch_main_queue_callback_4CF + 1844
14 CoreFoundation 0x1840ac1f8 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE
+ 12
15 CoreFoundation 0x1840aa060 __CFRunLoopRun + 1628
16 CoreFoundation 0x183fd8ca0 CFRunLoopRunSpecific + 384
17 GraphicsServices 0x18f55c088 GSEventRunModal + 180
18 UIKit 0x1896f0ffc UIApplicationMain + 204
19 jswipe 0x100044a8c main (main.m:17)
20 libdyld.dylib 0x199de28b8 start + 4

@hannahmbanana
Copy link
Contributor

@klivin: Thanks for reporting this! Sorry for the delay in response. Are you a part of the ASDK Slack Channel (#1582)? We're usually able to respond on there within an hour or two. :)

@appleguy: any ideas here?

@appleguy
Copy link
Contributor

@klivin: Do you know what iOS versions this is occurring on? There are some known issues in iOS 7 and iOS 8 text API. Can you check if this is also occurring at the same frequency on iOS 9 or if there are a disproportionate number on older versions?

@maicki
Copy link
Contributor

maicki commented Jun 30, 2016

@appleguy You think this is more related to the locking issues in ASTextNode we had? Setting an attributed string triggers a redraw ...

@appleguy
Copy link
Contributor

appleguy commented Jul 1, 2016

@klivin Two things:

  • setAttributedText: is ideal to call on a background thread. This can be done when the cell is first created by ensuring you're using the nodeBlockForItemAtIndexPath: API (make sure any accesses to the data source that you need the indexPath for are done OUTSIDE the block - e.g. to get the data model that you want to set on the cell, you should do this outside the block). The stacks you shared show that the main thread is waiting because it is setting text on a node that is currently drawing, which is not ideal; if you have a common need to update the text of an already-onscreen element, it's probably worth it to do a dispatch_async before you actually set the text.
  • There are some important fixes to ASTextNode locking in the master branch that should resolve this crash. We never found a reproduction case for it, and it seemed fairly rare, in that although it did occur in volume for the Pinterest app it was never a top crash (and we have never found that repro case). The fixes will be in the 1.9.81 release, but because of the holiday weekend, this might not go out until next week. Nonetheless we are shipping Pinterest on the current master and believe it is in stable condition at this time, so I encourage you to update if this crash is affecting your app. It is very possible (even likely) that the somewhat atypical access pattern in the stacks, updating the existing text while drawing, makes your app more likely to trigger the crash than most — so it's especially worth it to use master for now.

@maicki
Copy link
Contributor

maicki commented Jul 16, 2016

@klivin Hey, Can you please update us on this issue? Do you still see crashes in your app after using the latest release? Thanks!

@hannahmbanana
Copy link
Contributor

@klivin: I'm going to close this thread given the amount of time since it's been active. However, if you still see this crash, could you re-open this issue and let us know? Thanks!

@klivin
Copy link
Author

klivin commented Aug 16, 2016

@hannahmbanana @maicki @appleguy Thanks, and sorry for the delay on the update here. Yes you guys must have fixed the locking issue as the crash has gone away in the most recent release using the master branch at the time. I believe this was fixed on master 3-4 weeks ago.

This is probably appropriate for another place, and I'll create a new issue - I have been having a general issue with ASTextNode around auto-scale text. I am setting the text with variable length text, and am trying to use the pointSizeScaleFactors to achieve an auto-scale of the text. I am seeing that the entire text node size changes, I want the size of the text node to stay fixed and the text size to grow/shrink to fit. I am trying using layoutSpecThatFits to specify the text node size, but the text node size appears to be determined by the text length, not the layout spec.

@klivin
Copy link
Author

klivin commented Aug 16, 2016

Here's link to new issue, thanks!

#2077

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants