[iOS] UIWindow is still around after destroying the UIViewComponentPeer

Hi, I was investigating a crash in our app happening in JuceUIViewController::isKioskModeView():

    JuceUIView* juceView = (JuceUIView*) [c view];
    jassert (juceView != nil && juceView->owner != nullptr);

    return Desktop::getInstance().getKioskModeComponent() == &(juceView->owner->getComponent());

in which the juceView has no owner.

It seems that the problem is caused by a UIWindow still being around after destroying the view’s UIViewComponentPeer, because (since iOS 13) a UIWindow is not deallocated until it’s removed from its UIWindowScene.

So a possible fix is in juce_ios_UIViewComponentPeer.mm:565

    if (! isSharedWindow)
    {
        [((JuceUIWindow*) window) setOwner: nil];
        if (@available(iOS 13.0, *)) {
            window.windowScene = nil;
        }
        [window release];
    }

The change looks reasonable, but I’d like to try to reproduce the crash to make sure that I understand what’s actually breaking.

Please can you provide a set of steps which cause a JUCE app to break in this way?

I’ve just seen this appear in a JUCE app on iOS, and can confirm that this fix appears to resolve the issue.

1 Like

I just ran into this crash on our iOS app. It happened when closing the bluetooth devices pop-up. The fix above fixed the crash, but oddly enough when that window is showing, the iOS status top bar also shows, even though it’s usually hidden. It does go away when you close the bluetooth pop-up…

Will the above fix be in develop relatively soon? Thanks!

I’ve merged this patch now:

Please let me know if this doesn’t resolve the issue you’re seeing.

It does fix the crash :tada: , but I still see the status bar, which is a bit odd but not really an issue. I’m also noticing these messages in the debugger every time I open the bluetooth dialog, which I don’t think I was seeing when using directly the JUCE version 6.0.8 commit…

Unbalanced calls to begin/end appearance transitions for <JuceUIViewController: 0x10fda1ab0>.

I can also report that the crash with the bluetooth dialog is fixed now.