7

I'm getting these crash reports from XCode (I pasted one at the bottom) and I can't reproduce the error or figure out what the problem is.

From the backtrace I'm thinking it could be related to the decodeObject stuff… I did have some problems with the new decodeBool and decodeDouble functions, so to be sure I made an NSCoder extension:

func safeDecodeDouble(key: String) -> Double? {
    if self.containsValue(forKey: key) {
        if let value = self.decodeObject(forKey: key) as? Double {
            return value
        }
        return self.decodeDouble(forKey: key)
    }
    return nil
}

func safeDecodeBool(key: String) -> Bool? {
    if self.containsValue(forKey: key) {
        if let value = self.decodeObject(forKey: key) as? Bool {
            return value
        }
        return self.decodeBool(forKey: key)
    }
    return nil
}

func safeDecodeDate(key: String) -> Date? {
    if self.containsValue(forKey: key) {
        if let value = self.decodeObject(forKey: key) as? Date {
            return value
        }
    }
    return nil
}

func safeDecodeString(key: String) -> String? {
    if self.containsValue(forKey: key) {
        if let value = self.decodeObject(forKey: key) as? String {
            return value
        }
    }
    return nil
}

Now I only use the safeDecode functions in my code, but I'm still getting those same crash reports.

The third item in the backtrace says [UIStoryboard storyboardWithName:bundle:], but I don't know what that could have to do with anything. Also every crash report has something about state restoration and decodeObject, so I'm thinking the problem isn't the storyboard instantiation per se.

At the same time I never have any problems when I test state restoration on the simulator or on my devices, so apparently it's only happening to some people.

Any ideas on what could be going on here?


Last Exception Backtrace:
0   CoreFoundation                  0x18a146fd8 __exceptionPreprocess + 124 (NSException.m:165)
1   libobjc.A.dylib                 0x188ba8538 objc_exception_throw + 56 (objc-exception.mm:521)
2   UIKit                           0x190a36850 +[UIStoryboard storyboardWithName:bundle:] + 776 (UIStoryboard.m:99)
3   UIKit                           0x190bfacfc -[_UIStoryboardProxy initWithCoder:] + 192 (UIStateRestorationSupport.m:324)
4   Foundation                      0x18ab96420 _decodeObjectBinary + 2076 (NSKeyedArchiver.m:2304)
5   Foundation                      0x18ab95b58 _decodeObject + 308 (NSKeyedArchiver.m:2467)
6   UIKit                           0x1903e62ec -[UIStateRestorationKeyedUnarchiver decodeObjectForKey:] + 88 (UIStateRestorationSupport.m:454)
7   UIKit                           0x1903e5ba8 -[UIApplication(StateRestoration) _restoreApplicationPreservationStateWithSessionIdentifier:beginHandler:completionHandler:] + 4772 (UIApplication.m:13551)
8   UIKit                           0x1902e76b4 -[UIApplication(StateRestoration) _doRestorationIfNecessary] + 244 (UIApplication.m:13979)
9   UIKit                           0x1902e7288 -[UIApplication _handleDelegateCallbacksWithOptions:isSuspended:restoreState:] + 296 (UIApplication.m:1792)
10  UIKit                           0x1904f3800 -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 3452 (UIApplication.m:2129)
11  UIKit                           0x1904f92a8 -[UIApplication _runWithMainScene:transitionContext:completion:] + 1684 (UIApplication.m:3625)
12  UIKit                           0x19050dde0 __84-[UIApplication _handleApplicationActivationWithScene:transitionContext:completion:]_block_invoke.3151 + 48 (UIApplication.m:10365)
13  UIKit                           0x1904f653c -[UIApplication workspaceDidEndTransaction:] + 168 (UIApplication.m:2990)
14  FrontBoardServices              0x18bcef884 __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__ + 36 (FBSSerialQueue.m:158)
15  FrontBoardServices              0x18bcef6f0 -[FBSSerialQueue _performNext] + 176 (FBSSerialQueue.m:177)
16  FrontBoardServices              0x18bcefaa0 -[FBSSerialQueue _performNextFromRunLoopSource] + 56 (FBSSerialQueue.m:206)
17  CoreFoundation                  0x18a0f5424 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 24 (CFRunLoop.c:1943)
18  CoreFoundation                  0x18a0f4d94 __CFRunLoopDoSources0 + 540 (CFRunLoop.c:1989)
19  CoreFoundation                  0x18a0f29a0 __CFRunLoopRun + 744 (CFRunLoop.c:2821)
20  CoreFoundation                  0x18a022d94 CFRunLoopRunSpecific + 424 (CFRunLoop.c:3113)
21  UIKit                           0x1902e045c -[UIApplication _run] + 652 (UIApplication.m:2658)
22  UIKit                           0x1902db130 UIApplicationMain + 208 (UIApplication.m:4089)
23  Leio                            0x1000b6ecc main + 120 (BookInfoTableViewController.swift:19)
24  libdyld.dylib                   0x18903159c start + 4

Edit: Here's a different crash report that showed up and suggests there really is a problem with state restoration. I can never reproduce it myself, though. :/

0   CoreFoundation                  0x18385adb0 __exceptionPreprocess + 124 (NSException.m:162)
1   libobjc.A.dylib                 0x182ebff80 objc_exception_throw + 56 (objc-exception.mm:531)
2   Foundation                      0x1841d4704 -[NSCoder(Exceptions) __failWithException:] + 132 (NSCoder.m:544)
3   Foundation                      0x1841d48bc -[NSCoder(Exceptions) __failWithExceptionName:errorCode:format:] + 440 (NSCoder.m:580)
4   Foundation                      0x1841a33b8 _decodeObjectBinary + 2996 (NSKeyedArchiver.m:2173)
5   Foundation                      0x1841a274c _decodeObject + 304 (NSKeyedArchiver.m:2313)
6   UIKit                           0x188b3e20c -[UIStateRestorationKeyedUnarchiver decodeObjectForKey:] + 88 (UIStateRestorationSupport.m:454)
7   UIKit                           0x188b3daf8 -[UIApplication(StateRestoration) _restoreApplicationPreservationStateWithSessionIdentifier:beginHandler:completionHandler:] + 4908 (UIApplication.m:15043)
8   UIKit                           0x188a32d44 -[UIApplication(StateRestoration) _doRestorationIfNecessary] + 244 (UIApplication.m:15471)
9   UIKit                           0x188a32964 -[UIApplication _handleDelegateCallbacksWithOptions:isSuspended:restoreState:] + 308 (UIApplication.m:1860)
10  UIKit                           0x188c62184 -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 2904 (UIApplication.m:2112)
11  UIKit                           0x188c665f0 -[UIApplication _runWithMainScene:transitionContext:completion:] + 1684 (UIApplication.m:3355)
12  UIKit                           0x188c63764 -[UIApplication workspaceDidEndTransaction:] + 168 (UIApplication.m:2748)
13  FrontBoardServices              0x1851fb7ac __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__ + 36 (FBSSerialQueue.m:158)
14  FrontBoardServices              0x1851fb618 -[FBSSerialQueue _performNext] + 168 (FBSSerialQueue.m:177)
15  FrontBoardServices              0x1851fb9c8 -[FBSSerialQueue _performNextFromRunLoopSource] + 56 (FBSSerialQueue.m:206)
16  CoreFoundation                  0x18381109c __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 24 (CFRunLoop.c:1761)
17  CoreFoundation                  0x183810b30 __CFRunLoopDoSources0 + 540 (CFRunLoop.c:1807)
18  CoreFoundation                  0x18380e830 __CFRunLoopRun + 724 (CFRunLoop.c:2536)
19  CoreFoundation                  0x183738c50 CFRunLoopRunSpecific + 384 (CFRunLoop.c:2814)
20  UIKit                           0x188a2b94c -[UIApplication _run] + 460 (UIApplication.m:2578)
21  UIKit                           0x188a26088 UIApplicationMain + 204 (UIApplication.m:3772)
22  Leio                            0x1000f6ecc main + 120 (BookInfoTableViewController.swift:19)
23  libdyld.dylib                   0x1832d68b8 start + 4 (start_glue.s:78)
dbmrq
  • 1,451
  • 13
  • 32
  • What is the description of the crash? The part before the stack trace? – Coder-256 Jun 14 '17 at 14:28
  • @Coder256 `Exception Type: EXC_CRASH (SIGABRT)` `Exception Codes: 0x0000000000000000, 0x0000000000000000` `Exception Note: EXC_CORPSE_NOTIFY` `Triggered by Thread: 0` – dbmrq Jun 14 '17 at 17:46
  • I have a hunch that you are having the same problem as [this question](https://stackoverflow.com/q/16554939/3398839). Could you check that and its solutions? – Coder-256 Jun 15 '17 at 13:30
  • @Coder256 Uhm, I'll look into it, thanks. But in my case Apple didn't catch the problem at their review. It's only happening in about 15 devices among 1000. I'll still check the storyboards though, you never know. – dbmrq Jun 15 '17 at 18:20
  • Some resources that may help: [link 1](https://github.com/bnickel/Restoration-Inspector), [link 2](https://developer.apple.com/documentation/uikit/uistoryboard/1616216-storyboardwithname?language=objc). Also, could the problem be that the saved state is not compatible between different versions of your app, so users get this crash when they upgrade and the state is restored from a previous version? Finally, what is line 19 of `BookInfoTableViewController.swift`? – Coder-256 Jun 15 '17 at 19:23
  • did you try to debug it? the `EXC_CRASH (SIGABRT)` means that your app is passing bad data somewhere – alecnash Jun 15 '17 at 21:18
  • @Coder256 Thanks for the links, I'll look into it soon and come back with the results. The crash happens multiple times on the same (few) devices, so I don't think the problem is the app version. And line 19 is just the class declaration. – dbmrq Jun 16 '17 at 05:03
  • @alecnash I don't know how to, since I can't reproduce the problem myself. – dbmrq Jun 16 '17 at 05:04
  • This is strange. Why is your `BookInfoTableViewController` calling `UIApplicationMain`? Is it the main view controller? I am just asking because it seems strange that the main view controller would be a `UITableViewController`, which I'm guessing it is in your case. – Coder-256 Jun 16 '17 at 14:05
  • @Coder256 No, as far as I can tell it *shouldn't* be calling `UIApplicationMain`... at least I didn't knowingly do anything to cause that. I assumed it had something to do with state restoration. – dbmrq Jun 16 '17 at 18:20
  • It could appear that way if it is `BookInfoTableViewController` is the main view controller, is it? – Coder-256 Jun 16 '17 at 21:48
  • @Coder256 No, it's not. ‍♂️ – dbmrq Jun 17 '17 at 04:56
  • I'm thinking this could have something to do with the restoration identifier in an intermediary view controller. I checked a hundred times and I was sure I had set identifiers for all of them, but I just realized there's a different way to get to `BookInfoTableViewController` passing by a vc that doesn't have one. That still doesn't cause that crash here, but I don't know. I'll send a new version to the App Store and see if it still happens. – dbmrq Jun 17 '17 at 18:32
  • Just a hunch , have u done localization of storyboard ? could you remove get to default and try – Saket Kumar Jun 20 '17 at 15:28
  • @saketkumar Thanks for your help. I just did that, but since I can't reproduce the error myself I don't know if it helped. We'll find out when I get the next version on the App Store, haha. – dbmrq Jun 20 '17 at 16:44
  • Can it be caused by renaming storyboard or bundle at some point? So users that updated from the old to a new version can not load a newly named resource from their archives containing the old name. – Zapko Jun 21 '17 at 01:47
  • @Zapko I don't think so, since it happens multiple times on the same devices. – dbmrq Jun 21 '17 at 01:57

0 Answers0