From ffdfafc4b47b8267395370199073c292da33dd42 Mon Sep 17 00:00:00 2001 From: Jan Moeller Date: Thu, 6 Apr 2023 09:27:16 +0200 Subject: [PATCH] Ignore removed/changed screens if no QIOSIntegration instance exists QIOSTracker registers itself as handlers for system notifications about changes of the screen environment. If no QIOSIntegration instance exists, newly detected screens are not added to the list of known screens (see screenConnected()). This, in turn, will result in a crash if a screen is disconnected and removed in screenDisconnected() as it is not known to qtPlatformScreenFor() and the function returns a nullptr. Consider the QIOSIntegration also whenever a screen is "changed". This is more of a safety measure do avoid crashes for unknown screens. This situation occurs if an iOS device is used to mirror the display via AirPlay and no actual QGuiApplication exists, e.g. Qt is only embedded in a Framework. Pick-to: 6.5 6.2 Fixes: QTBUG-106701 Change-Id: Id778fc5afa7c284b0536ee02b1ba2c10321cc5b1 Reviewed-by: Volker Hilsheimer Reviewed-by: Lars Schmertmann --- src/plugins/platforms/ios/qiosscreen.mm | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/plugins/platforms/ios/qiosscreen.mm b/src/plugins/platforms/ios/qiosscreen.mm index e968cafe1d..8a034a98bc 100644 --- a/src/plugins/platforms/ios/qiosscreen.mm +++ b/src/plugins/platforms/ios/qiosscreen.mm @@ -81,6 +81,9 @@ static QIOSScreen* qtPlatformScreenFor(UIScreen *uiScreen) + (void)screenDisconnected:(NSNotification*)notification { + if (!QIOSIntegration::instance()) + return; + QIOSScreen *screen = qtPlatformScreenFor([notification object]); Q_ASSERT_X(screen, Q_FUNC_INFO, "Screen disconnected that we didn't know about"); @@ -89,6 +92,9 @@ static QIOSScreen* qtPlatformScreenFor(UIScreen *uiScreen) + (void)screenModeChanged:(NSNotification*)notification { + if (!QIOSIntegration::instance()) + return; + QIOSScreen *screen = qtPlatformScreenFor([notification object]); Q_ASSERT_X(screen, Q_FUNC_INFO, "Screen changed that we didn't know about");