Prevent accessing destroyed WaylandSurface in WaylandSurfaceItem.
authorSamuel Rødal <samuel.rodal@nokia.com>
Fri, 8 Apr 2011 11:05:03 +0000 (13:05 +0200)
committerSamuel Rødal <samuel.rodal@nokia.com>
Fri, 8 Apr 2011 11:18:12 +0000 (13:18 +0200)
src/qt-compositor/compositor_api/waylandsurfaceitem.cpp
src/qt-compositor/compositor_api/waylandsurfaceitem.h

index de9579e..d0c41d0 100644 (file)
@@ -138,6 +138,7 @@ void WaylandSurfaceItem::init(WaylandSurface *surface)
     setFlag(ItemHasContents);
     setAcceptedMouseButtons(Qt::LeftButton | Qt::RightButton);
     connect(surface, SIGNAL(mapped(const QRect &)), this, SLOT(surfaceMapped(const QRect &)));
+    connect(surface, SIGNAL(destroyed(QObject *)), this, SLOT(surfaceDestroyed(QObject *)));
     connect(m_textureProvider, SIGNAL(textureChanged()), this, SLOT(update()));
 }
 
@@ -158,35 +159,40 @@ QSGTextureProvider *WaylandSurfaceItem::textureProvider() const
 
 void WaylandSurfaceItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
 {
-    m_surface->sendMousePressEvent(toSurface(event->pos()), event->button());
+    if (m_surface)
+        m_surface->sendMousePressEvent(toSurface(event->pos()), event->button());
 }
 
 void WaylandSurfaceItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
 {
-    m_surface->sendMouseMoveEvent(toSurface(event->pos()));
+    if (m_surface)
+        m_surface->sendMouseMoveEvent(toSurface(event->pos()));
 }
 
 void WaylandSurfaceItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
 {
-    m_surface->sendMouseReleaseEvent(toSurface(event->pos()), event->button());
+    if (m_surface)
+        m_surface->sendMouseReleaseEvent(toSurface(event->pos()), event->button());
 }
 
 void WaylandSurfaceItem::keyPressEvent(QKeyEvent *event)
 {
-    if (hasFocus())
+    if (m_surface && hasFocus())
         m_surface->sendKeyPressEvent(event->nativeScanCode());
 }
 
 void WaylandSurfaceItem::keyReleaseEvent(QKeyEvent *event)
 {
-    if (hasFocus())
+    if (m_surface && hasFocus())
         m_surface->sendKeyReleaseEvent(event->nativeScanCode());
 }
 
 void WaylandSurfaceItem::takeFocus()
 {
     setFocus(true);
-    m_surface->setInputFocus();
+
+    if (m_surface)
+        m_surface->setInputFocus();
 }
 
 QPoint WaylandSurfaceItem::toSurface(const QPointF &pos) const
@@ -200,6 +206,11 @@ void WaylandSurfaceItem::surfaceMapped(const QRect &rect)
     setHeight(rect.height());
 }
 
+void WaylandSurfaceItem::surfaceDestroyed(QObject *)
+{
+    m_surface = 0;
+}
+
 QSGNode *WaylandSurfaceItem::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *)
 {
     QSGImageNode *node = static_cast<QSGImageNode *>(oldNode);
index aa9b8a4..357538d 100644 (file)
@@ -77,6 +77,7 @@ public slots:
 
 private slots:
     void surfaceMapped(const QRect &rect);
+    void surfaceDestroyed(QObject *object);
 
 protected:
     QSGNode *updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *);