diff options
author | Christian Strømme <christian.stromme@qt.io> | 2023-04-03 16:51:16 +0200 |
---|---|---|
committer | Christian Strømme <christian.stromme@qt.io> | 2023-04-04 18:14:56 +0200 |
commit | f1dc42e19e7757fb5d2845fa0cc3f782e7521aa7 (patch) | |
tree | 8a7618adc77da4e546ffa409674665ad8b0ba080 | |
parent | 87103e04e9c34630bd51ae5f8e7550033976c6bf (diff) |
Fix crash in QIOSTextResponder
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 <richard.gustavsen@qt.io>
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
-rw-r--r-- | src/plugins/platforms/ios/qiostextresponder.mm | 8 |
1 files 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<QUIView *>(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<QUIView *>(qApp->focusWindow()->handle()->winId()) : 0; } // ------------------------------------------------------------------------- |