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 {
    guard let rootViewController = window.rootViewController else {

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

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

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