From: Samuel Rødal Date: Fri, 8 Apr 2011 11:05:03 +0000 (+0200) Subject: Prevent accessing destroyed WaylandSurface in WaylandSurfaceItem. X-Git-Tag: qt-v5.0.0-alpha1~319 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=dd278cb7a242577a780f9c2325f0562f6123c4d7;p=profile%2Fivi%2Fqtwayland.git Prevent accessing destroyed WaylandSurface in WaylandSurfaceItem. --- diff --git a/src/qt-compositor/compositor_api/waylandsurfaceitem.cpp b/src/qt-compositor/compositor_api/waylandsurfaceitem.cpp index de9579e..d0c41d0 100644 --- a/src/qt-compositor/compositor_api/waylandsurfaceitem.cpp +++ b/src/qt-compositor/compositor_api/waylandsurfaceitem.cpp @@ -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(oldNode); diff --git a/src/qt-compositor/compositor_api/waylandsurfaceitem.h b/src/qt-compositor/compositor_api/waylandsurfaceitem.h index aa9b8a4..357538d 100644 --- a/src/qt-compositor/compositor_api/waylandsurfaceitem.h +++ b/src/qt-compositor/compositor_api/waylandsurfaceitem.h @@ -77,6 +77,7 @@ public slots: private slots: void surfaceMapped(const QRect &rect); + void surfaceDestroyed(QObject *object); protected: QSGNode *updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *);