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>
This commit is contained in:
Christian Strømme 2023-04-03 16:51:16 +02:00
parent 87103e04e9
commit f1dc42e19e

View File

@ -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;
}
// -------------------------------------------------------------------------