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

Crash on D3D11 swapChain when using WA_NativeWindow on QWebEngineView hosted in a QDockWidget

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P1: Critical P1: Critical
    • None
    • 6.8.3
    • None
    • Windows

      In the code sample below there are two webview hosted in dockwidgets, one is docked by default and the other is floating.
      Note that both webviews have the WA_NativeWindow flag set, so the the QMainWindow can stay on raster surface, not changing surface type.

      Observations on WebView 1 initially docked:

      • Docked it resizes and renders properly 
      • Undocked the webengine view is not rendering anymore

      Observations on WebView 2 initially floating:

      • Undocked/floating it resizes and renders properly
      • When docking back, e.g. into the right docking area, it crashes on the D3D11 swapChain being null, see attached screenshot

       
      Repo code sample:

      #include <QtWidgets/QApplication>
      #include <QtWidgets/QtWidgets>
      #include <QWebEngineView>
      
      class CenterWidget : public QWidget
      {
      public:
      	CenterWidget(QWidget* parent = nullptr)
      		: QWidget(parent) {}
      
      	void paintEvent(QPaintEvent *event)
      	{
      		 QPainter painter(this);
      		 painter.setPen(Qt::white);
      		 QRect _rect = rect();
      		 painter.fillRect(_rect, QColor(100,100,100));
      		 if (auto win = parentWidget()->windowHandle())
      		 {
      			 QString surfaceStr("Unhandled");
      			 switch (win->surfaceType())
      			 {
      			 case QWindow::RasterSurface:
      				 surfaceStr = "Raster";
      				 break;
      			 case QWindow::Direct3DSurface:
      				 surfaceStr = "Direct3D";
      				 break;
      			 case QWindow::OpenGLSurface:
      				 surfaceStr = "OpenGL";
      				 break;
      			 }
      			 painter.drawText(_rect, "Surface Type: " + surfaceStr, QTextOption(Qt::AlignCenter));
      		 }
      	}
      };
      
      int main(int argc, char* argv[])
      {
      	QApplication::setAttribute(Qt::AA_DontCreateNativeWidgetSiblings);
      	QApplication app(argc, argv);
      	app.setQuitOnLastWindowClosed(true);
      
      	// Create Top Level MainWindow
      	auto mainWindow = new QMainWindow();
      	mainWindow->setAttribute(Qt::WA_DeleteOnClose);
      	mainWindow->setWindowTitle(QString("WebView Bugs - Qt%1.%2.%3").arg(QT_VERSION_MAJOR).arg(QT_VERSION_MINOR).arg(QT_VERSION_PATCH));
      	mainWindow->setCentralWidget(new CenterWidget(mainWindow));
      	mainWindow->resize(800, 600);
      	mainWindow->show();
      
      	// Create WebView 1 - Initially docked in the QMainWindow -> un-dock will not render WebView anymore
      	auto webView1 = new QWebEngineView();
      	webView1->load(QUrl("https://qt-project.org/"));
      	webView1->setAttribute(Qt::WA_NativeWindow); // For keeping raster surface on mainWindow
      	
      	auto dockWidget1 = new QDockWidget("WebView 1", mainWindow);
      	dockWidget1->setAllowedAreas(Qt::AllDockWidgetAreas);
      	mainWindow->addDockWidget(Qt::LeftDockWidgetArea, dockWidget1);
      	dockWidget1->setWidget(webView1);
      	
      	// Create WebView 2 - Initially floating on top of the QMainWindow -> re-dock will crash on swapChain
      	auto webView2 = new QWebEngineView();
      	webView2->load(QUrl("https://qt-project.org/"));
      	webView2->setAttribute(Qt::WA_NativeWindow); // For keeping raster surface on mainWindow
      
      	auto dockWidget2 = new QDockWidget("WebView 2", mainWindow);
      	dockWidget2->setAllowedAreas(Qt::AllDockWidgetAreas);
      	mainWindow->addDockWidget(Qt::RightDockWidgetArea, dockWidget2);
      	dockWidget2->setWidget(webView2);
      	dockWidget2->setFloating(true);
      	
      	// Run Qt message loop
      	return app.exec();
      }
      

       

        1. Screen Recording 2025-06-06 120051.mp4
          11.09 MB
          Roman Woelker
        2. Screenshot 2025-06-06 120442.png
          753 kB
          Roman Woelker
        3. QTBUG-137463_with_webview.zip
          2 kB
          Senthil Kannan Kandaswamy
        4. rhi_workaround_patch1.diff
          7 kB
          Roman Woelker
        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

            lagocs Laszlo Agocs
            roman_w Roman Woelker
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:

                There are no open Gerrit changes