square/Aardvark

iOS 9 Crash: -[ARKLogDistributor logScreenshot]

dfed opened this issue · 3 comments

dfed commented

Hit this crash last night on iOS 9 while trying to file a bug:

Thread : Fatal Exception: CALayerInvalidGeometry – sublayer with non-finite position [inf inf]
0  CoreFoundation                 0x00000001826dcf5c __exceptionPreprocess
1  libobjc.A.dylib                0x00000001972cff80 objc_exception_throw
2  CoreFoundation                 0x00000001826dcea4 -[NSException initWithCoder:]
3  QuartzCore                     0x0000000187481a94 -[CALayer _renderSublayersInContext:]
4  QuartzCore                     0x0000000187480ac0 -[CALayer renderInContext:]
5  QuartzCore                     0x0000000187481a60 -[CALayer _renderSublayersInContext:]
6  QuartzCore                     0x0000000187480ac0 -[CALayer renderInContext:]
7  QuartzCore                     0x0000000187481a60 -[CALayer _renderSublayersInContext:]
8  QuartzCore                     0x0000000187480ac0 -[CALayer renderInContext:]
9  QuartzCore                     0x0000000187481a60 -[CALayer _renderSublayersInContext:]
10 QuartzCore                     0x0000000187480ac0 -[CALayer renderInContext:]
11 QuartzCore                     0x0000000187481a60 -[CALayer _renderSublayersInContext:]
12 QuartzCore                     0x0000000187480ac0 -[CALayer renderInContext:]
13 Cash                           0x00000001002d7b8c -[ARKLogDistributor logScreenshot] (ARKLogDistributor.m:249)
14 Cash                           0x00000001002dc8d4 ARKLogScreenshot (Aardvark.m:49)
15 Cash                           0x00000001002d2f48 -[ARKEmailBugReporter composeBugReport] (ARKEmailBugReporter.m:100)
16 Cash                           0x00000001002dde24 -[UIApplication(ARKAdditions) _ARK_didFireBugReportGestureRecognizer:] (UIApplication+ARKAdditions.m:105)
17 UIKit                          0x000000018818bb28 _UIGestureRecognizerSendTargetActions
18 UIKit                          0x0000000187dd2a5c _UIGestureRecognizerSendActions
19 UIKit                          0x0000000187c656ac -[UIGestureRecognizer _updateGestureWithEvent:buttonEvent:]
20 UIKit                          0x000000018818ce78 ___UIGestureRecognizerUpdate_block_invoke809
21 UIKit                          0x0000000187c25118 _UIGestureRecognizerRemoveObjectsFromArrayAndApplyBlocks
22 UIKit                          0x0000000187c231ec _UIGestureRecognizerUpdate
23 CoreFoundation                 0x0000000182693c30 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__
24 CoreFoundation                 0x00000001826919d4 __CFRunLoopDoObservers
25 CoreFoundation                 0x0000000182691e04 __CFRunLoopRun
26 CoreFoundation                 0x00000001825c0dc0 CFRunLoopRunSpecific
27 GraphicsServices               0x000000018d714088 GSEventRunModal
28 UIKit                          0x0000000187c9af60 UIApplicationMain
29 Cash                           0x00000001002c3d80 main (main.mm:28)
30 libdyld.dylib                  0x0000000197afa8b8 start

Likely a layout bug in the app or iOS 9 – a layer with an infinite size is odd, to say the least. Looking into this today. Plan is to try/catch logging the screenshot so we don't crash on bug-file. I'll also look into whether there are other screen capture mechanisms we could use (short of requiring camera roll access).

This crash was reliably reproducible on one screen in my app. Was not reproducible in other screens.

dfed commented

This happens when a rect of a layer/view is set to CGRectNull. This is something to avoid in your app. Use CGRectZero. Our app hit this because titleRectForContentRect: was returning a CGRectInset where the inset was greater than the size of the content we were insetting.

I am having the same problem. I was trying to take a snapshot of a scrollview. it throw me the same error.

class scrollScreenShot {
    class func take(scrollview:UIScrollView)->UIImage{

        var image: UIImage? = nil
        UIGraphicsBeginImageContextWithOptions(scrollview.contentSize,false,0.0)
        let savedContentOffset: CGPoint = scrollview.contentOffset
        let savedFrame: CGRect = scrollview.frame
        scrollview.contentOffset = CGPointZero
        scrollview.frame = CGRectMake(0, 0, scrollview.contentSize.width, scrollview.contentSize.height)

        //this is where is problem is

        scrollview.layer.renderInContext(UIGraphicsGetCurrentContext()!)
        image = UIGraphicsGetImageFromCurrentImageContext()
        scrollview.contentOffset = savedContentOffset
        scrollview.frame = savedFrame
        UIGraphicsEndImageContext()
        return image!;

    }

}

dfed commented

@harryyuanfeng run the following in the debugger: [scrollview recursiveDescription]. Look for a view with inf in the coordinate space. That'll help you find the bad view.