3

Update: 14th April 2016: Still seeing these crashes in Fabric Crashlytics, and still not sure how I would go about fixing. Seems to be a session crash rate of 0.2%.


As far as I can see, my app is very occasionally crashing when Apple takes a snapshot (as the snippet below is in the crash log). However, I'm not sure how I can stop it from crashing.

[UIApplication _updateSnapshotAndStateRestorationArchiveForBackgroundEvent:saveState:exitIfCouldNotRestoreState:]

I have found a few other posts on SO, but I don't use any kind of WebView (post), does not use any ads, and calls the completionHandler in the main thread. etc. Other people also seem to experience similar issues, but their post remains unanswered. The entire crash log is below. Is this a bug with Apple's internals, or is it something which I can potentially fix?

Thread : Crashed: com.apple.main-thread
0  libsystem_platform.dylib       0x1812962a0 _platform_memmove + 176
1  CoreFoundation                 0x181544ed8 CFDataGetBytes + 172
2  CoreFoundation                 0x181544ed8 CFDataGetBytes + 172
3  ImageIO                        0x182cb599c CGImageReadGetBytesAtOffset + 624
4  ImageIO                        0x182cb570c CGImageReadSessionGetBytes + 36
5  ImageIO                        0x182d89acc iioReadCallback + 32
6  AppleJPEG                      0x182c8bd04 aj_istream_move_to_position + 488
7  AppleJPEG                      0x182c8c968 aj_istream_state_restore + 60
8  AppleJPEG                      0x182c9b64c applejpeg_decode_set_ra_table + 804
9  ImageIO                        0x182d8e1e0 copyImageBlockSetAppleJPEG + 6524
10 ImageIO                        0x182cbf130 ImageProviderCopyImageBlockSetCallback + 852
11 QuartzCore                     0x183d5ae0c CA::Render::create_image(CGImage*, CGColorSpace*, unsigned int) + 972
12 QuartzCore                     0x183d59eec CA::Render::copy_image(CGImage*, CGColorSpace*, unsigned int, double) + 372
13 QuartzCore                     0x183d32f00 -[CALayer(CALayerPrivate) _copyRenderLayer:layerFlags:commitFlags:] + 484
14 QuartzCore                     0x183d32c54 CA::Context::commit_layer(CA::Layer*, unsigned int, unsigned int, void*) + 108
15 QuartzCore                     0x183d2f9cc CA::Layer::commit_if_needed(CA::Transaction*, void (*)(CA::Layer*, unsigned int, unsigned int, void*), void*) + 392
16 QuartzCore                     0x183d2f95c CA::Layer::commit_if_needed(CA::Transaction*, void (*)(CA::Layer*, unsigned int, unsigned int, void*), void*) + 280
17 QuartzCore                     0x183d2f95c CA::Layer::commit_if_needed(CA::Transaction*, void (*)(CA::Layer*, unsigned int, unsigned int, void*), void*) + 280
18 QuartzCore                     0x183d2f95c CA::Layer::commit_if_needed(CA::Transaction*, void (*)(CA::Layer*, unsigned int, unsigned int, void*), void*) + 280
19 QuartzCore                     0x183d2f95c CA::Layer::commit_if_needed(CA::Transaction*, void (*)(CA::Layer*, unsigned int, unsigned int, void*), void*) + 280
20 QuartzCore                     0x183d2f95c CA::Layer::commit_if_needed(CA::Transaction*, void (*)(CA::Layer*, unsigned int, unsigned int, void*), void*) + 280
21 QuartzCore                     0x183d2f95c CA::Layer::commit_if_needed(CA::Transaction*, void (*)(CA::Layer*, unsigned int, unsigned int, void*), void*) + 280
22 QuartzCore                     0x183d2f95c CA::Layer::commit_if_needed(CA::Transaction*, void (*)(CA::Layer*, unsigned int, unsigned int, void*), void*) + 280
23 QuartzCore                     0x183d2f95c CA::Layer::commit_if_needed(CA::Transaction*, void (*)(CA::Layer*, unsigned int, unsigned int, void*), void*) + 280
24 QuartzCore                     0x183d2f95c CA::Layer::commit_if_needed(CA::Transaction*, void (*)(CA::Layer*, unsigned int, unsigned int, void*), void*) + 280
25 QuartzCore                     0x183d2f95c CA::Layer::commit_if_needed(CA::Transaction*, void (*)(CA::Layer*, unsigned int, unsigned int, void*), void*) + 280
26 QuartzCore                     0x183d2f95c CA::Layer::commit_if_needed(CA::Transaction*, void (*)(CA::Layer*, unsigned int, unsigned int, void*), void*) + 280
27 QuartzCore                     0x183d2f95c CA::Layer::commit_if_needed(CA::Transaction*, void (*)(CA::Layer*, unsigned int, unsigned int, void*), void*) + 280
28 QuartzCore                     0x183d2f95c CA::Layer::commit_if_needed(CA::Transaction*, void (*)(CA::Layer*, unsigned int, unsigned int, void*), void*) + 280
29 QuartzCore                     0x183d2d0cc CA::Context::commit_transaction(CA::Transaction*) + 1332
30 QuartzCore                     0x183d2c9dc CA::Transaction::commit() + 512
31 UIKit                          0x1865ab768 _UIWindowUpdateVisibleContextOrder + 236
32 UIKit                          0x1865ab5b4 +[UIWindow _prepareWindowsPassingTestForAppResume:] + 32
33 UIKit                          0x1865e1468 __114-[UIApplication _updateSnapshotAndStateRestorationArchiveForBackgroundEvent:saveState:exitIfCouldNotRestoreState:]_block_invoke_3 + 72
34 libdispatch.dylib              0x181089630 _dispatch_call_block_and_release + 24
35 libdispatch.dylib              0x1810895f0 _dispatch_client_callout + 16
36 libdispatch.dylib              0x18108ecf8 _dispatch_main_queue_callback_4CF + 1844
37 CoreFoundation                 0x1815ecbb0 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 12
38 CoreFoundation                 0x1815eaa18 __CFRunLoopRun + 1628
39 CoreFoundation                 0x181519680 CFRunLoopRunSpecific + 384
40 GraphicsServices               0x182a28088 GSEventRunModal + 180
41 UIKit                          0x186390d90 UIApplicationMain + 204
42 MyApp                          0x100095888 main (main.m:16)
43 libdispatch.dylib              0x1810ba8b8 (Missing)
Community
  • 1
  • 1
cjhill
  • 1,004
  • 2
  • 9
  • 31

1 Answers1

1

It's a pretty good bet that something somewhere is triggering UIKit manipulations on a background thread. Finding exactly what ... well that's a trick. With a little luck, this gist may be of help.

This is a guard that tracks down UIKit access on threads other than main. This snippet is taken from the commercial iOS PDF framework http://pspdfkit.com, but relicensed under MIT. Works because a lot of calls internally call setNeedsDisplay or setNeedsLayout. Won't catch everything, but it's very lightweight and usually does the job.

If you have any ad display SDKs in your app, that would be an excellent first suspicion. They have a depressing habit of being absolutely horrible at correctly confining UI manipulations to the main thread.

Alex Curylo
  • 4,744
  • 1
  • 27
  • 37
  • Thanks, @alexcurylo, the app does not use any kind of Ads or WebViews, but I'll try the gist and see what it brings up. – cjhill Apr 19 '16 at 08:26
  • I did find one instance of the UI updating in a background thread - so it potentially could be that. That's a really useful Gist, though, so thanks for that! – cjhill Apr 19 '16 at 12:56
  • This "fix" went like a week ago, but unfortunately has not fixed the sporadic crash reports coming in. – cjhill May 31 '16 at 13:37