RHI renderer: fix crash in Renderer::sendShaderChangesToFrontend()

The Shaders or the QShaderProgramBuilders may not exist in the managers
anymore by the time we arrive in
Renderer::sendShaderChangesToFrontend(). This happens when Qt3D shuts
down.

To fix this, check the returned values by the managers.

This is similar to the existing patch for the OpenGL renderer:
Ia021cd8f22ceb2626a7a2734b7e346fbcc8e0301

Pick-to: 6.4
Change-Id: I322bf2524016c1f98433891ad230b65272fabbdd
Reviewed-by: Paul Lemire <paul.lemire@kdab.com>
This commit is contained in:
Aurélien Brooke 2022-12-11 13:42:25 +01:00
parent 1fe1c5a375
commit 643d7889cc
1 changed files with 6 additions and 0 deletions

View File

@ -1528,6 +1528,9 @@ void Renderer::sendShaderChangesToFrontend(Qt3DCore::QAspectManager *manager)
const std::vector<HShader> &activeShaders = m_nodesManager->shaderManager()->activeHandles(); const std::vector<HShader> &activeShaders = m_nodesManager->shaderManager()->activeHandles();
for (const HShader &handle : activeShaders) { for (const HShader &handle : activeShaders) {
Shader *s = m_nodesManager->shaderManager()->data(handle); Shader *s = m_nodesManager->shaderManager()->data(handle);
if (!s)
continue;
if (s->requiresFrontendSync()) { if (s->requiresFrontendSync()) {
QShaderProgram *frontend = QShaderProgram *frontend =
static_cast<decltype(frontend)>(manager->lookupNode(s->peerId())); static_cast<decltype(frontend)>(manager->lookupNode(s->peerId()));
@ -1545,6 +1548,9 @@ void Renderer::sendShaderChangesToFrontend(Qt3DCore::QAspectManager *manager)
for (const ShaderBuilderUpdate &update : m_shaderBuilderUpdates) { for (const ShaderBuilderUpdate &update : m_shaderBuilderUpdates) {
QShaderProgramBuilder *builder = QShaderProgramBuilder *builder =
static_cast<decltype(builder)>(manager->lookupNode(update.builderId)); static_cast<decltype(builder)>(manager->lookupNode(update.builderId));
if (!builder)
continue;
QShaderProgramBuilderPrivate *dBuilder = QShaderProgramBuilderPrivate *dBuilder =
static_cast<decltype(dBuilder)>(QNodePrivate::get(builder)); static_cast<decltype(dBuilder)>(QNodePrivate::get(builder));
dBuilder->setShaderCode(update.shaderCode, update.shaderType); dBuilder->setShaderCode(update.shaderCode, update.shaderType);