NSMutableRLEArray outof bounds when transitioning views

This code is causing my iOS app to crash. The only error I'm getting is Terminating app due to uncaught exception 'NSRangeException', reason: 'NSMutableRLEArray objectAtIndex:effectiveRange:: Out of bounds' and I can't figure out what's going wrong.

Any ideas?

    guard let window = UIApplication.shared.keyWindow else {
        return
    }
    guard let rootViewController = window.rootViewController else {
        return
    }

    let storyboard = UIStoryboard(name: "Main", bundle: nil)
    let vc = storyboard.instantiateViewController(withIdentifier: "MyViewControllerIdentifier")
    vc.view.frame = rootViewController.view.frame
    vc.view.layoutIfNeeded()

    UIView.transition(with: window, duration: 0.3, options: .transitionCrossDissolve, animations: {
        window.rootViewController = vc
    }, completion: { completed in
        print("completed")
    })

EDIT: Oddly enough trying to change ViewControllers with a segue makes the app crash too.