From 8b06a07b2427750ed5cd58e438494567408d0039 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20O=2E=20Cordero=20P=C3=A9rez?= Date: Thu, 9 Jan 2025 03:12:38 -0400 Subject: [PATCH] Re-enable ability to switch render modes under Qt 6 Fixes #880, where QSG_VISUALIZE overdraw, and other modes, were not working. Also fixes race condition crashes around use of OpenGL RHI and scene graph events. --- plugins/quickinspector/quickinspector.cpp | 29 +++++++++++++---------- 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/plugins/quickinspector/quickinspector.cpp b/plugins/quickinspector/quickinspector.cpp index f578f941c..012d620a2 100644 --- a/plugins/quickinspector/quickinspector.cpp +++ b/plugins/quickinspector/quickinspector.cpp @@ -301,25 +301,30 @@ void RenderModeRequest::apply() if (connection) disconnect(connection); -#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) - // crashes in qrhigles2..bindShaderResources sometimes - return; -#endif - - if (window && window->rendererInterface()->graphicsApi() != QSGRendererInterface::OpenGL) - return; - if (window) { - emit aboutToCleanSceneGraph(); + switch (window->rendererInterface()->graphicsApi()) { + // Compatible render interfaces + case QSGRendererInterface::OpenGL: + break; + default: + return; + } + const QByteArray mode = renderModeToString(RenderModeRequest::mode); QQuickWindowPrivate *winPriv = QQuickWindowPrivate::get(window); - QMetaObject::invokeMethod(window, "cleanupSceneGraph", Qt::DirectConnection); #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) - winPriv->visualizationMode = mode; + QObject::connect(window.get(), &QQuickWindow::beforeSynchronizing, this, [this, winPriv, mode](){ + emit aboutToCleanSceneGraph(); + QMetaObject::invokeMethod(window, "cleanupSceneGraph", Qt::DirectConnection); + winPriv->visualizationMode = mode; + emit sceneGraphCleanedUp(); + }, static_cast(Qt::DirectConnection | Qt::SingleShotConnection)); #else + emit aboutToCleanSceneGraph(); + QMetaObject::invokeMethod(window, "cleanupSceneGraph", Qt::DirectConnection); winPriv->customRenderMode = mode; -#endif emit sceneGraphCleanedUp(); +#endif } QMetaObject::invokeMethod(this, "preFinished", Qt::QueuedConnection);