From 36852d78bfe20bbb5eebc2bd8cf9ee4ebae4db50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Wed, 3 Nov 2021 17:14:34 +0100 Subject: [PATCH] iOS: Defer restoring screen mirroring until next runloop pass Associating the UIWindow with a different screen will trigger layout of the child views of the window, including the view that we're in the process of removing, which doesn't have a platform window anymore. Instead of protecting every possible code path in the view code with checks for a platform window we defer the restoring of mirror mode until after the view has been removed. Pick-to: 6.2 5.15 Task-number: QTBUG-94530 Change-Id: I8c66106cafa67e06721e621c019b2d10acf02326 Reviewed-by: Timur Pocheptsov --- src/plugins/platforms/ios/qiosviewcontroller.mm | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/plugins/platforms/ios/qiosviewcontroller.mm b/src/plugins/platforms/ios/qiosviewcontroller.mm index 7aeb3b9ca6..64d42d6b65 100644 --- a/src/plugins/platforms/ios/qiosviewcontroller.mm +++ b/src/plugins/platforms/ios/qiosviewcontroller.mm @@ -147,9 +147,13 @@ UIWindow *uiWindow = self.window; if (uiWindow.screen != [UIScreen mainScreen] && self.subviews.count == 1) { - // Removing the last view of an external screen, go back to mirror mode - uiWindow.screen = [UIScreen mainScreen]; - uiWindow.hidden = YES; + // We're about to remove the last view of an external screen, so go back + // to mirror mode, but defer it until after the view has been removed, + // to ensure that we don't try to layout the view that's being removed. + dispatch_async(dispatch_get_main_queue(), ^{ + uiWindow.screen = [UIScreen mainScreen]; + uiWindow.hidden = YES; + }); } }