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

Crash when dereferencing a deleted QRhi after native window is re-created

    XMLWordPrintable

Details

    • macOS, Windows
    • 075dc6d6f (tqtc/lts-6.5), c3b1e96df (tqtc/lts-6.5), 0d342e831 (dev), df2314d70 (6.7), e34b15f0b (6.6), b26b2be7c (tqtc/lts-6.5)
    • G&UI Finishing 2023

    Description

      Please use this to reproduce.

      #include <QtWidgets/QApplication>
      #include <QtWidgets/QWidget>
      #include <QtOpenGLWidgets/QOpenGLWidget>
      #include <QtCore/QTimer>
      #include <QtWebEngineWidgets/QWebEngineView>
      #include <QtQuick/QQuickWindow>
      
      int main(int argc, char** argv)
      {
      	QQuickWindow::setGraphicsApi(QSGRendererInterface::OpenGL);
      	QApplication app(argc, argv);
      
      	// tlw: red.
      	QWidget tlw;
      	tlw.resize(640, 480);
      	tlw.setStyleSheet("QWidget { background-color: red; }");
      
      	// quick: cause tlw to be opengl and own an opengl rhi
      	QWebEngineView web1(&tlw);
      	web1.setUrl(QUrl("chrome://gpu"));
      	web1.setGeometry(0, 0, 640, 240);
      
      	// workspace: raster by default
      	QWidget workspace(&tlw);
      	workspace.setGeometry(0, 240, 640, 240);
      	workspace.winId();
      	workspace.setStyleSheet("QWidget { background-color: blue; }");
      	
      	// wait for the quick to refresh. defer to page loaded.
      	QObject::connect(&web1, &QWebEngineView::loadFinished, [&]() {
      		// gl: cause tlw & workspace window to be re-created. rhi is deleted.
      		// Qt crash when using the deleted rhi.
      		QOpenGLWidget* gl = new QOpenGLWidget(&workspace);
      		gl->setGeometry(0, 0, 640, 240);
      	});
      
      	tlw.show();
      	return app.exec();
      }
      

      QOpenGLWidget is not mandatory. Here is an example using webengine only

      #include <QtWidgets/QApplication>
      #include <QtWidgets/QWidget>
      #include <QtWebEngineWidgets/QWebEngineView>
      
      int main(int argc, char** argv)
      {
      	QApplication app(argc, argv);
      
      	// tlw: red.
      	QWidget tlw;
      	tlw.resize(640, 480);
      	tlw.setStyleSheet("QWidget { background-color: red; }");
      
      	// quick: cause tlw to be opengl and own an opengl rhi
      	QWebEngineView web1(&tlw);
      	web1.setUrl(QUrl("chrome://gpu"));
      	web1.setGeometry(0, 0, 640, 240);
      
      	// workspace: raster by default
      	QWidget workspace(&tlw);
      	workspace.setGeometry(0, 240, 640, 240);
      	workspace.winId();
      	workspace.setStyleSheet("QWidget { background-color: blue; }");
      	
      	// wait for the quick to refresh. defer to page loaded.
      	QObject::connect(&web1, &QWebEngineView::loadFinished, [&]() {
      		QWebEngineView* web2 = new QWebEngineView(&workspace);
      		web2->setGeometry(0, 0, 640, 240);
      		web2->setUrl(QUrl("chrome://gpu"));
      	});
      
      	tlw.show();
      	return app.exec();
      }
      

      Crash stack:

      (lldb) bt 10
      * thread #1, name = 'CrBrowserMain', queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=EXC_I386_GPFLT)
        * frame #0: 0x0000000102b37d67 QtGui`QRhi::isRecordingFrame(this=0x0000600000013420) const at qrhi.cpp:7641:15 [opt]
          frame #1: 0x00000001032d22cb QtQuick`QQuickRenderControl::beginFrame(this=<unavailable>) at qquickrendercontrol.cpp:620:28 [opt]
          frame #2: 0x0000000100a45bb6 QtQuickWidgets`QQuickWidgetPrivate::render(this=0x0000000101b29a30, needsSync=true) at qquickwidget.cpp:346:24 [opt]
          frame #3: 0x0000000100a46691 QtQuickWidgets`QQuickWidgetPrivate::renderSceneGraph(this=0x0000000101b29a30) at qquickwidget.cpp:404:5 [opt]
          frame #4: 0x00000001010f2ad7 QtCore`QObject::event(this=0x0000600002932990, e=0x00007ff7bfefd928) at qobject.cpp:1415:9 [opt]
          frame #5: 0x00000001003718da QtWidgets`QWidget::event(this=0x0000600002932990, event=0x00007ff7bfefd928) at qwidget.cpp:9381:25 [opt]
          frame #6: 0x0000000100a49cb7 QtQuickWidgets`QQuickWidget::event(this=0x0000600002932990, e=0x00007ff7bfefd928) at qquickwidget.cpp:1725:21 [opt]
          frame #7: 0x00000001000a3541 QtWebEngineWidgets`QtWebEngineCore::WebEngineQuickWidget::event(this=0x0000600002932990, event=0x00007ff7bfefd928) at qwebengineview.cpp:345:30 [opt]
          frame #8: 0x000000010031eb77 QtWidgets`QApplicationPrivate::notify_helper(this=<unavailable>, receiver=0x0000600002932990, e=0x00007ff7bfefd928) at qapplication.cpp:3290:26 [opt]
          frame #9: 0x000000010031fa13 QtWidgets`QApplication::notify(this=0x00007ff7bfeff260, receiver=<unavailable>, e=<unavailable>) at qapplication.cpp:0 [opt]
      

      Attachments

        Issue Links

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

          Activity

            People

              vestbo Tor Arne Vestbø
              mingxiang Mingxiang Xu
              Votes:
              1 Vote for this issue
              Watchers:
              13 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: