7

Since a few days I've been experiencing a very strange crash when debugging our app within Xcode 11.

Situation

We have an app built for iOS 11 and higher. But since Xcode 11 the app is crashing on setting the root view controller. But when I open the app after it crashed, the app does work so it seems it has something to do with setup a debug session.

The device where I try to build on is an iPhone Xs, with iOS 13.1.2. I also tried another device with 13.1 but having the same issue there.

However, when I attach a device that is running on 12.x.x it's working.

Strangely, yesterday I was able to run on a simulator. But since today the same crash occures on a device (iPhone Xs).

Also maybe important to mention: colleagues of me that work with the same project, do not have the same issues. (!!)

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

// Show app loading view controller
self.window = [[RMWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.rootViewController = [[AppLoadingViewController alloc] init]; // Thread 1: EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)
[self.window makeKeyAndVisible];

I tried the following:

  • Replaced AppDelegate.h/m by AppDelegate.swift.
  • Update all project settings to latest settings from Xcode 11.
  • Tried a plain UIViewController() instead of AppLoadingViewController().
  • Cleaned Derived Folder (hardcore style)
  • Clean all Xcode cache
  • Reinstall Xcode
  • Restarted Mac + iPhone
  • Removed the iOS DeviceSupport folder from Xcode preferences, re-connected device via 'Devices and Simulators'.
  • Created a new project and run on iPhone, DOES work.

This is an app that contains both Objective-C and Swift code, we have it already for years. But it's the first time that something like this is happening.

Is there anyone who has an idea of what this could be?

Ashish Kakkad
  • 23,586
  • 12
  • 103
  • 136
NielsKoole
  • 296
  • 4
  • 11
  • Aren't u signing with a Distribution Certificate ? – CZ54 Oct 03 '19 at 11:48
  • 3
    Does it crash on `rootViewController` setter, or in `AppLoadingViewController` initializer? – mag_zbc Oct 03 '19 at 11:49
  • I'm using development certifcate (newly created within dev portal for Xcode 11). It crashes on the rootViewController setter, not inside the `AppLoadingViewController`. The AppLoadingViewController is basically empty with only an Image in the .xib file. – NielsKoole Oct 03 '19 at 11:52
  • Can you provide the crash log? – CZ54 Oct 03 '19 at 11:53
  • You're using a custom `UIWindow` subclass. Perhaps you have a custom `rootViewController` setter? – mag_zbc Oct 03 '19 at 11:57
  • Try download/git checkout "fresh" version of your project , maybe you have some strange settings in files which are ignored by source control? – Michcio Oct 03 '19 at 12:02
  • #0 0x000000019ee0e1a4 in _os_unfair_lock_recursive_abort () -> #34 0x00000001a31d4c50 in -[UIWindow setRootViewController:] () -> #35 0x00000001049e5224 in -[AppDelegate application:didFinishLaunchingWithOptions:] – NielsKoole Oct 03 '19 at 12:06
  • When I replace the custom UIWindow with the original UIWindow, same issue occurs. – NielsKoole Oct 03 '19 at 12:07
  • I had a similar issue. See if this helps: https://stackoverflow.com/a/58117854/3241041 – alxlives Oct 03 '19 at 12:12
  • 1
    I found that question indeed, but did not work for me. I also just did a clean clone from the repository and tried to get that one working, but did not work as well. – NielsKoole Oct 03 '19 at 12:41
  • 1
    In iOS 13, you should not be creating the window or setting the root view controller in the app delegate. That needs to be done in the scene delegate (unless you've take steps to completely opt out of using scenes). – rmaddy Oct 03 '19 at 15:05
  • I've made sure that we are completely opted out for using scenes. The thing is: it seems that it has something to do with UIKit. The crash always happens at the very first time something from UIKit is called. But UIKit is linked within the Linked Binary Build phase. Anyone has a lead on this? – NielsKoole Oct 08 '19 at 14:03
  • I am experiencing a crash after long pressing any text in any TextView or TextField that only occurs while debugging. After archiving the same code, all works as expected (no crash at all). XCode 11 and Catalina have many strange bugs... – Miguel Isla Oct 16 '19 at 13:31
  • I have found why it was crashing. It was not a debug/release thing. I have set some breakpoints in the breakpoint pane that caused some exceptions ¿? when long pressing on a UITextView or UITextField. Any clue why? Sorry to mix things that have nothing to do with the original question. – Miguel Isla Oct 16 '19 at 14:01

2 Answers2

2
    let homeVC = UIStoryboard(name:"Main", bundle: nil).instantiateViewController(withIdentifier: "SigninViewController") as! SigninViewController
    let navC = UINavigationController(rootViewController: homeVC)
    navC.navigationBar.isHidden = true
    UIApplication.shared.windows.first?.rootViewController = navC
    UIApplication.shared.windows.first?.makeKeyAndVisible()

try this it is working Fine in my case..

  • I had missed the makeKeyAndVisible() function, while this didn't help the poster as they had a mac specific error, this was very helpful. – C. Skjerdal Jan 23 '20 at 23:20
0

After spending days on this I have clean installed Mac OS Catalina. This did fix it. I still don't know what the actual problem was, but to potentially save a lot of time for others I suggest doing the same.

If somebody found the solution I would still like to know.

NielsKoole
  • 296
  • 4
  • 11