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
Change-Id: I704c3597b46e465ddf2605bdb71a21cb36cb2a26
Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
(cherry picked from commit f1dc42e19e7757fb5d2845fa0cc3f782e7521aa7)
This commit is contained in:
Christian Strømme 2023-04-03 16:51:16 +02:00
parent 5708f4f093
commit 16a7e8d3d5

View File

@ -368,8 +368,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;
}
// -------------------------------------------------------------------------