From 077067bc8f68a3146430b941ea0f0daa61781f91 Mon Sep 17 00:00:00 2001 From: Andy Nichols Date: Tue, 5 Jun 2012 15:41:59 +0200 Subject: [PATCH 1/1] A few fixes to prevent compositor crashes MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit If a client application exits abruptly while in direct rendering mode, the surface buffer could reference a null buffer. We now check for this before attempting to use such a surface buffer. It is also possible for WaylandSurfaceNode::preprocess to be called after WaylandSurfaceItem has called surfaceDestroyed, so now we check for a valid surface in preprocess as well. Change-Id: Ibca71349b7a24687944f8b6cd505941b580e0c2a Reviewed-by: Paul Olav Tvete Reviewed-by: Jørgen Lind --- src/compositor/compositor_api/waylandsurfacenode.cpp | 10 ++++++---- src/compositor/wayland_wrapper/wlsurface.cpp | 18 ++++++++++-------- src/compositor/wayland_wrapper/wlsurfacebuffer.cpp | 3 +++ 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/src/compositor/compositor_api/waylandsurfacenode.cpp b/src/compositor/compositor_api/waylandsurfacenode.cpp index e657175..a4063cc 100644 --- a/src/compositor/compositor_api/waylandsurfacenode.cpp +++ b/src/compositor/compositor_api/waylandsurfacenode.cpp @@ -39,10 +39,12 @@ void WaylandSurfaceNode::preprocess() { QMutexLocker locker(WaylandSurfaceItem::mutex); - //Update if the item is dirty and we haven't done an updateTexture for this frame - if (m_item && m_item->m_damaged && !m_textureUpdated) { - m_item->updateTexture(); - updateTexture(); + if (m_item && m_item->surface()) { + //Update if the item is dirty and we haven't done an updateTexture for this frame + if (m_item->m_damaged && !m_textureUpdated) { + m_item->updateTexture(); + updateTexture(); + } } //Reset value for next frame: we have not done updatePaintNode yet m_textureUpdated = false; diff --git a/src/compositor/wayland_wrapper/wlsurface.cpp b/src/compositor/wayland_wrapper/wlsurface.cpp index 579c27b..ff13e01 100644 --- a/src/compositor/wayland_wrapper/wlsurface.cpp +++ b/src/compositor/wayland_wrapper/wlsurface.cpp @@ -377,14 +377,16 @@ SurfaceBuffer *Surface::createSurfaceBuffer(struct wl_buffer *buffer) bool Surface::postBuffer() { #ifdef QT_COMPOSITOR_WAYLAND_GL if (m_waylandSurface->handle() == m_compositor->directRenderSurface()) { - SurfaceBuffer *surfaceBuffer = m_backBuffer? m_backBuffer : m_frontBuffer; - if (surfaceBuffer && m_compositor->pageFlipper()) { - if (m_compositor->pageFlipper()->displayBuffer(surfaceBuffer)) { - surfaceBuffer->setPageFlipperHasBuffer(true); - m_compositor->setDirectRenderingActive(true); - return true; - } else { - qDebug() << "could not post buffer"; + SurfaceBuffer *surfaceBuffer = currentSurfaceBuffer(); + if (surfaceBuffer && surfaceBuffer->waylandBufferHandle()) { + if (m_compositor->pageFlipper()) { + if (m_compositor->pageFlipper()->displayBuffer(surfaceBuffer)) { + surfaceBuffer->setPageFlipperHasBuffer(true); + m_compositor->setDirectRenderingActive(true); + return true; + } else { + qDebug() << "could not post buffer"; + } } } } diff --git a/src/compositor/wayland_wrapper/wlsurfacebuffer.cpp b/src/compositor/wayland_wrapper/wlsurfacebuffer.cpp index ced3ed2..61e241c 100644 --- a/src/compositor/wayland_wrapper/wlsurfacebuffer.cpp +++ b/src/compositor/wayland_wrapper/wlsurfacebuffer.cpp @@ -199,6 +199,9 @@ void SurfaceBuffer::handleDisplayed() void *SurfaceBuffer::handle() const { + if (!m_buffer) + return 0; + if (!m_handle) { SurfaceBuffer *that = const_cast(this); if (isShmBuffer()) { -- 2.7.4