Avoid crash when windows with active mouse synthesization are deleted
authorLaszlo Agocs <laszlo.p.agocs@nokia.com>
Fri, 10 Feb 2012 11:40:20 +0000 (13:40 +0200)
committerQt by Nokia <qt-info@nokia.com>
Fri, 10 Feb 2012 18:39:57 +0000 (19:39 +0100)
Some QtQuick autotests, that apparently generate incomplete touch
sequences and delete windows without finishing them, triggered a crash
when handling the TouchCancel event in QGuiApplication.

Change-Id: Ie725d5a16f55acc40bdc8e2c38f93daac9477f2a
Reviewed-by: Samuel Rødal <samuel.rodal@nokia.com>
src/gui/kernel/qguiapplication.cpp
src/gui/kernel/qguiapplication_p.h

index b17cf58..0e525da 100644 (file)
@@ -975,7 +975,9 @@ void QGuiApplicationPrivate::processTouchEvent(QWindowSystemInterfacePrivate::To
         if (!self->synthesizedMousePoints.isEmpty() && !e->synthetic) {
             for (QHash<QWindow *, SynthesizedMouseData>::const_iterator synthIt = self->synthesizedMousePoints.constBegin(),
                  synthItEnd = self->synthesizedMousePoints.constEnd(); synthIt != synthItEnd; ++synthIt) {
-                QWindowSystemInterfacePrivate::MouseEvent fake(synthIt.key(),
+                if (!synthIt->window)
+                    continue;
+                QWindowSystemInterfacePrivate::MouseEvent fake(synthIt->window.data(),
                                                                e->timestamp,
                                                                synthIt->pos,
                                                                synthIt->screenPos,
@@ -1159,7 +1161,7 @@ void QGuiApplicationPrivate::processTouchEvent(QWindowSystemInterfacePrivate::To
                     if (touchPoint.id() == m_fakeMouseSourcePointId) {
                         if (b != Qt::NoButton)
                             self->synthesizedMousePoints.insert(w, SynthesizedMouseData(
-                                                                    touchPoint.pos(), touchPoint.screenPos()));
+                                                                    touchPoint.pos(), touchPoint.screenPos(), w));
                         QWindowSystemInterfacePrivate::MouseEvent fake(w, e->timestamp,
                                                                        touchPoint.pos(),
                                                                        touchPoint.screenPos(),
index 3ca007f..66db843 100644 (file)
@@ -201,9 +201,11 @@ public:
     QHash<ActiveTouchPointsKey, ActiveTouchPointsValue> activeTouchPoints;
     QEvent::Type lastTouchType;
     struct SynthesizedMouseData {
-        SynthesizedMouseData(const QPointF &p, const QPointF &sp) : pos(p), screenPos(sp) { }
+        SynthesizedMouseData(const QPointF &p, const QPointF &sp, QWindow *w)
+            : pos(p), screenPos(sp), window(w) { }
         QPointF pos;
         QPointF screenPos;
+        QWeakPointer<QWindow> window;
     };
     QHash<QWindow *, SynthesizedMouseData> synthesizedMousePoints;