From f1dc42e19e7757fb5d2845fa0cc3f782e7521aa7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Str=C3=B8mme?= Date: Mon, 3 Apr 2023 16:51:16 +0200 Subject: [PATCH] Fix crash in QIOSTextResponder MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When a window that has focus is destroyed we can end up calling into nextResponder where the focus window is in the process of being destroyed, so make sure we have a window with a valid platform window before calling winId() Fixes: QTBUG-110019 Pick-to: 6.5 6.4 Change-Id: I704c3597b46e465ddf2605bdb71a21cb36cb2a26 Reviewed-by: Richard Moe Gustavsen Reviewed-by: Tor Arne Vestbø --- src/plugins/platforms/ios/qiostextresponder.mm | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/plugins/platforms/ios/qiostextresponder.mm b/src/plugins/platforms/ios/qiostextresponder.mm index f8bcf7fb25..cea79e7e91 100644 --- a/src/plugins/platforms/ios/qiostextresponder.mm +++ b/src/plugins/platforms/ios/qiostextresponder.mm @@ -222,8 +222,12 @@ - (UIResponder*)nextResponder { - return qApp->focusWindow() ? - reinterpret_cast(qApp->focusWindow()->handle()->winId()) : 0; + // Make sure we have a handle/platform window before getting the winId(). + // In the dtor of QIOSWindow the platform window is set to null before calling + // removeFromSuperview which will end up calling nextResponder. That means it's + // possible that we can get here while the window is being torn down. + return (qApp->focusWindow() && qApp->focusWindow()->handle()) ? + reinterpret_cast(qApp->focusWindow()->handle()->winId()) : 0; } // -------------------------------------------------------------------------