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

[Reg 6.2.9 -> 6.5.2] QQuickWidget can crash when calling winId() in a native event filter (on Windows)

    XMLWordPrintable

Details

    • Windows

    Description

      Code

      #include <windows.h>
      #include <QAbstractNativeEventFilter>
      #include <QApplication>
      #include <QQuickWidget>
      #include <QMainWindow>
      
      class MyNativeEventFilter : public QAbstractNativeEventFilter
      {
      public:
          bool nativeEventFilter(const QByteArray&, void* message, qintptr*)
          {
              auto msg = (MSG*)message;
              QWidget* widget = QWidget::find(WId(msg->hwnd));
              if (widget)
                  qDebug() << widget << widget->winId(); // WORKAROUND 1: Avoid calling winId() here
              return false;
          }
      };
      
      int main(int argc, char *argv[])
      {
          //QQuickWindow::setGraphicsApi(QSGRendererInterface::OpenGL);
      
          QApplication app(argc, argv);
          app.installNativeEventFilter(new MyNativeEventFilter);
      
          QMainWindow mainWindow;
      	
          // NOTE: mainWindow.winId() changes after each line below. Not sure if this is relevant.
          mainWindow.setWindowState(Qt::WindowMaximized); // WORKAROUND 2: Call this line AFTER the QQuickWidget is constructed
          mainWindow.setCentralWidget(new QQuickWidget);
          mainWindow.show();
      
          return app.exec();
      }
      

       

      Outcomes on Qt 6.5.2/6.6.0b3
      After a running the code above for a few seconds, it will crash.

      If the OpenGL RHI backend is chosen, we will also see the following warning:

      QOpenGLContext::makeCurrent() called with non-opengl surface 0x2b5ff73c540
      QRhiGles2: Failed to make context current. Expect bad things to happen.
      Failed to create QRhi for QBackingStoreRhiSupport
      

      Attachments

        1. qtbug117078_diag.diff
          3 kB
        2. qtbug117078_log.txt
          4 kB
        3. qtbug117078_opengl_stack.txt
          21 kB
        4. qtbug117078_stack.txt
          29 kB
        5. qtbug117078.zip
          2 kB

        Issue Links

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

          Activity

            People

              kleint Friedemann Kleint
              skoh-qt Sze Howe Koh
              Votes:
              2 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes