react-native icon indicating copy to clipboard operation
react-native copied to clipboard

occasional crash in [RCTText drawRect]

Open ide opened this issue 11 years ago • 14 comments

The onLayout demo crashed in the iPhone 6 simulator using Xcode 6.3.1 with iOS 8.3. Before this I had cleaned DerivedData and run git clean -dfx && npm install in a checkout of react-native@41612f37b0c31320b025043df9e954df540db171.

cc @sahrens

May  8 14:31:31 mac.local UIExplorer[61720]: *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** NSRunStorage, _NSBlockNumberForIndex(): index (72) beyond array bounds (23)'
    *** First throw call stack:
    (
        0   CoreFoundation                      0x000000010f731c65 __exceptionPreprocess + 165
        1   libobjc.A.dylib                     0x000000010eba3bb7 objc_exception_throw + 45
        2   CoreFoundation                      0x000000010f731b9d +[NSException raise:format:] + 205
        3   UIFoundation                        0x0000000117ac9adb _NSBlockNumberForIndex + 84
        4   UIFoundation                        0x0000000117ab6a1f -[NSLayoutManager _primitiveInvalidateDisplayForGlyphRange:] + 777
        5   UIFoundation                        0x0000000117ab8338 -[NSLayoutManager invalidateDisplayForCharacterRange:] + 450
        6   UIFoundation                        0x0000000117a8146a -[NSLayoutManager(NSPrivate) _invalidateDisplayIfNeeded] + 72
        7   UIFoundation                        0x0000000117aba83c -[NSLayoutManager textContainerForGlyphAtIndex:effectiveRange:] + 871
        8   UIFoundation                        0x0000000117abc6aa -[NSLayoutManager glyphRangeForTextContainer:] + 317
        9   UIExplorer                          0x000000010e56fbb7 -[RCTText drawRect:] + 231
        10  UIKit                               0x0000000111212612 -[UIView(CALayerDelegate) drawLayer:inContext:] + 495
        11  QuartzCore                          0x0000000110ed2a1a -[CALayer drawInContext:] + 119
        12  QuartzCore                          0x0000000110dcc93b CABackingStoreUpdate_ + 2793
        13  QuartzCore                          0x0000000110ed2923 ___ZN2CA5Layer8display_Ev_block_invoke + 59
        14  QuartzCore                          0x0000000110ed27ae _ZN2CA5Layer8display_Ev + 1478
        15  QuartzCore                          0x0000000110ec74c9 _ZN2CA5Layer17display_if_neededEPNS_11TransactionE + 301
        16  QuartzCore                          0x0000000110ec7551 _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 35
        17  QuartzCore                          0x0000000110e33886 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 242
        18  QuartzCore                          0x0000000110e34a3a _ZN2CA11Transaction6commitEv + 462
        19  QuartzCore                          0x0000000110e350eb _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 89
        20  CoreFoundation                      0x000000010f664ca7 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
        21  CoreFoundation                      0x000000010f664c00 __CFRunLoopDoObservers + 368
        22  CoreFoundation                      0x000000010f65aa33 __CFRunLoopRun + 1123
        23  CoreFoundation                      0x000000010f65a366 CFRunLoopRunSpecific + 470
        24  GraphicsServices                    0x000000011339ca3e GSEventRunModal + 161
        25  UIKit                               0x0000000111192900 UIApplicationMain + 1282
        26  UIExplorer                          0x000000010e4b5fff main + 111
        27  libdyld.dylib                       0x0000000112ca4145 start + 1
    )
May  8 14:31:55 mac com.apple.CoreSimulator.SimDevice.0AD0F9BD-A848-48A1-BFC6-BF8FABBF059A.launchd_sim[55138] (UIKitApplication:com.facebook.UIExplorer[0x89a0][61720]): Service exited due to signal: Killed: 9

ide avatar May 08 '15 21:05 ide

Weird, I don't think I've ever seen a stack like that before.

Can you quantify "Occasionally"?

sahrens avatar May 08 '15 23:05 sahrens

It happened the first time after cleaning my build artifacts and running the app, and then I wasn't able to repro after that. It might not be related to the onLayout demo (that [RCTText drawRect:] line is suspect) - that was just the demo that triggered the crash. If you guys have crash logs for the Groups app / Ads Manager is it possible to grep them for RCTText?

ide avatar May 08 '15 23:05 ide

Saw this same stack on a friend's app. Repros very intermittently; no idea what the cause is.

sophiebits avatar May 08 '15 23:05 sophiebits

@a2 based on RCTText.

sahrens avatar May 09 '15 00:05 sahrens

happened with me today ! crashed when I opened the UIExplorer app.

fkilaiwi avatar May 09 '15 15:05 fkilaiwi

This gist, which renders 100 <Text> nodes every frame, very reliably crashes for me (reload a few times if it doesn't crash immediately):

https://gist.github.com/spicyj/22bdcb6b229cd9dcbd6c

Not exactly the same stack, but it may be the same root cause. Looks like a threading issue with the shared TextKit objects across threads – in every crash I've seen with this sample app, the main thread and shadow queue are both processing text views. AsyncDisplayKit puts a lock around all TextKit operations which might be appropriate here too. Although I'm not sure if adding a lock is all that's needed – it seems a little fishy that these objects are even shared between RCTShadowText and RCTText because it seems like one thread could get ahead of the other and we could be trying to process shadow text with a new string before the last string has been rendered on the main thread. I don't have a complete grasp of the concurrency involved here though so I could be off base.

sophiebits avatar May 09 '15 17:05 sophiebits

Noticing a lot of these after the upgrade to 0.4.3; whereas before I only saw it occasionally, now it's crashing often.

The stack trace of the crash varies -- sometimes it's "!!! _NSGlyphTreeInsertGlyphs invalid char index", other times it's "_NSBlockNumberForIndex(): index (0) beyond array bounds (0) raised during typesetting layout manager"

ericflo avatar May 15 '15 21:05 ericflo

Ping @a2, @nicklockwood, @tadeuzagallo

sahrens avatar May 16 '15 03:05 sahrens

Not sure if this is related but have also discovered the following: EXC_BAD_ACCESS: RCTText line 90 - crashed with [_textStorage addLayoutManager:_layoutManager].

admmasters avatar May 26 '15 13:05 admmasters

Stack trace ends at: [NSLayoutManager(NSPrivate) _recalculateUsageForTextContainerAtIndex] - The main thread.

admmasters avatar May 26 '15 13:05 admmasters

Closing this because of https://github.com/facebook/react-native/commit/0689c0790edcc9cb8494e3f15300e2743556f442. Will reopen if the crash persists.

ide avatar May 28 '15 16:05 ide

I can provide context on ASDK/ComponentKit TextKit locking strategies if this crops up. Ping me, we have open radars with Apple.

ocrickard avatar Jul 04 '15 17:07 ocrickard

I should mention that I'm still seeing this in v0.33.1. It's definitely rare, but doesn't seem to be entirely fixed, and is one of the leading exceptions I have right now. (Slightly more often than the RCTImageLoader exception)

MattFoley avatar Jan 31 '17 21:01 MattFoley

Actually, I'm seeing a slightly different issue, in my case it's drawGlyphsForGlyphRange:atPoint: that is throwing the exception. I'm working on building a test project that reproduces it now.

Crashed: com.apple.main-thread
0  libobjc.A.dylib                0x18d8def70 objc_msgSend + 16
1  CoreText                       0x191b04bd4 CTFontDrawGlyphsAtPositions + 104
2  UIFoundation                   0x194c5d4c8 -[NSLayoutManager(OtherSupport) _showCGGlyphs:positions:count:font:matrix:attributes:inContext:] + 776
3  UIFoundation                   0x194ca81b0 -[NSLayoutManager showCGGlyphs:positions:count:font:matrix:attributes:inContext:] + 60
4  UIFoundation                   0x194c789b4 -[NSLayoutManager(NSPrivate) _drawGlyphsForGlyphRange:atPoint:] + 6016
5  MyApp                          0x100a076fc -[RCTText drawRect:] (RCTText.m:105)
6  UIKit                          0x194dcfa60 -[UIView(CALayerDelegate) drawLayer:inContext:] + 408
7  QuartzCore                     0x1921f559c -[CALayer drawInContext:] + 260
8  QuartzCore                     0x1920f6848 CABackingStoreUpdate_ + 2848
9  QuartzCore                     0x1921f516c ___ZN2CA5Layer8display_Ev_block_invoke + 52
10 QuartzCore                     0x1921f4e0c CA::Layer::display_() + 1524
11 QuartzCore                     0x1921ea314 CA::Layer::display_if_needed(CA::Transaction*) + 228
12 QuartzCore                     0x1921ea398 CA::Layer::layout_and_display_if_needed(CA::Transaction*) + 44
13 QuartzCore                     0x1921673e0 CA::Context::commit_transaction(CA::Transaction*) + 252
14 QuartzCore                     0x19218ea68 CA::Transaction::commit() + 512
15 QuartzCore                     0x19218f488 CA::Transaction::observer_callback(__CFRunLoopObserver*, unsigned long, void*) + 120
16 CoreFoundation                 0x18ee420c0 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 32
17 CoreFoundation                 0x18ee3fcf0 __CFRunLoopDoObservers + 372
18 CoreFoundation                 0x18ee40180 __CFRunLoopRun + 1024
19 CoreFoundation                 0x18ed6e2b8 CFRunLoopRunSpecific + 444
20 GraphicsServices               0x190822198 GSEventRunModal + 180
21 UIKit                          0x194db57fc -[UIApplication _run] + 684
22 UIKit                          0x194db0534 UIApplicationMain + 208

MattFoley avatar Jan 31 '17 21:01 MattFoley