Skip to content

Crash in updateViewHierarchy when window has no rootViewController #1157

@AdrianCurtin

Description

@AdrianCurtin

Description

When calling SVProgressHUD show methods, the HUD attempts to add its control view to the front window. If the window exists but its rootViewController is nil or in an invalid state, UIKit throws an NSInternalInconsistencyException during trait collection resolution.

Crash Details

The crash occurs in updateViewHierarchy at line 519:

[self.frontWindow addSubview:self.controlView];

Stack Trace

Fatal Exception: NSInternalInconsistencyException
UIKitCore _UIThemeKeyValueFromTraitCollection
UIKitCore -[UIDynamicCatalogSystemColor _resolvedColorWithTraitCollection:]
UIKitCore -[UIDynamicColor resolvedColorWithTraitCollection:]
...
UIKitCore -[UIView(Internal) _didMoveFromWindow:toWindow:]
...
SVProgressHUD.m:534 -[SVProgressHUD updateViewHierarchy]

Reproduction

This crash is difficult to reproduce but can occur when:

  1. SVProgressHUD is shown during app state transitions
  2. The key window exists but its rootViewController has been deallocated or is nil
  3. UIKit attempts to resolve trait collection for the new subview

Proposed Fix

Add a nil check for rootViewController before adding the subview:

UIWindow *window = self.frontWindow;
if (window.rootViewController) {
    [window addSubview:self.controlView];
}

Environment

  • iOS 17.x/18.x
  • SVProgressHUD master branch

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions