Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-73929

Race condition on window closing when using a threaded renderer

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P2: Important
    • None
    • 5.6
    • Quick: SceneGraph
    • None
    • Linux/Wayland
    • ca66d4fc23706a0f4ecfc4031f37cdd19facd836

    Description

      On SailfishOS, I sometimes get a segfault when closing a window. On this platform, a threaded renderer is used, over a Wayland implementation. Here is the backtrace at crash, from the renderer thread:

      0xb61e7556 in QMutex::lock() () from /usr/lib/libQt5Core.so.5
      (gdb) bt
      #0 0xb61e7556 in QMutex::lock() () from /usr/lib/libQt5Core.so.5
      #1 0xb3ed03c6 in QWaylandWindow::setCanResize(bool) () from /usr/lib/libQt5WaylandClient.so.5
      #2 0xb287291e in QWaylandGLContext::swapBuffers (this=0x72aee0, surface=<optimized out>) at ../../../../hardwareintegration/client/wayland-egl/qwaylandglcontext.cpp:517
      #3 0xb6976d12 in QOpenGLContext::swapBuffers(QSurface*) () from /usr/lib/libQt5Gui.so.5
      #4 0xb6cff77e in QSGRenderThread::syncAndRender (this=this@entry=0x5c59d8) at scenegraph/qsgthreadedrenderloop.cpp:636
      #5 0xb6cfff76 in QSGRenderThread::run (this=0x5c59d8) at scenegraph/qsgthreadedrenderloop.cpp:715
      

      We see that it's crashing in a call to swapBuffers() while accessing some internals of the platform window (here a QWaylandWindow). The issue is that the platform window has been deleted already by the main thread. It is visible by adding a break point in the destructor for instance.

      I believe this comes from the fact that the close event is not notifying the rendering thread that the resource are going to be destroyed. Indeed, looking at the code, if the close event is accepted, the close handler in QWindow will destroy the underlying platform window without notifying the QSGRenderer attribute 'windowManager'. This may cause the race condition if the renderer is a QSGThreadedRenderLoop because the platform window may be deleted while the thread is using it.

      I propose to correct this issue by notifying the QSGRenderer on a close event using the hide() method (which is supposed to release the resources according to documentation), see patch https://codereview.qt-project.org/#/c/253820/

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            janichol Andy Nichols
            dcaliste Damien Caliste
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes