File 0003-Fix-crash-when-a-custom-material-effect-shader-variable.patch of Package libqt5-qtquick3d.35247

From 5720c0da7e4eae5b997923815bbe7ebdfa00a079 Mon Sep 17 00:00:00 2001
From: Tomi Korpipaa <tomi.korpipaa@qt.io>
Date: Thu, 20 Apr 2023 06:58:27 +0300
Subject: [PATCH] Fix crash when a custom material / effect shader variable
 changes

We ended up deleting valid commands in cases where a shader variable
changed without the custom material or effect being deleted. Just redo
the to-be-deleted command list in updateSpatialNode instead of deleting
it.

Fixes: QTBUG-112969
Change-Id: Iec9bc584711325052f27353587632c4399b1fe4d
Reviewed-by: Andy Nichols <andy.nichols@qt.io>
---
 src/quick3d/qquick3dcustommaterial.cpp | 24 ++++++++++++++----------
 src/quick3d/qquick3deffect.cpp         | 24 ++++++++++++++----------
 2 files changed, 28 insertions(+), 20 deletions(-)

diff --git a/src/quick3d/qquick3dcustommaterial.cpp b/src/quick3d/qquick3dcustommaterial.cpp
index a2b1d3905..ed5ac9873 100644
--- a/src/quick3d/qquick3dcustommaterial.cpp
+++ b/src/quick3d/qquick3dcustommaterial.cpp
@@ -514,18 +514,22 @@ QSSGRenderGraphObject *QQuick3DCustomMaterial::updateSpatialNode(QSSGRenderGraph
 
     // We need to mark the commands that we allocated since they will need to be deallocted when the customMaterial is deleted.
     // We achieve this by filtering on the command type.
-    qDeleteAll(customMaterial->commandsToDelete);
+    // Just redo the list without deleting it, or we end up calling already deleted commands in
+    // render if a shader variable changes.
     customMaterial->commandsToDelete.clear();
     for (auto command : customMaterial->commands) {
-        if (command->m_type != dynamic::CommandType::AllocateBuffer &&
-                command->m_type != dynamic::CommandType::ApplyBufferValue &&
-                command->m_type != dynamic::CommandType::ApplyBlitFramebuffer &&
-                command->m_type != dynamic::CommandType::ApplyBlending &&
-                command->m_type != dynamic::CommandType::ApplyRenderState &&
-                command->m_type != dynamic::CommandType::ApplyCullMode &&
-                command->m_type != dynamic::CommandType::ApplyDepthValue &&
-                command->m_type != dynamic::CommandType::ApplyValue)
-        customMaterial->commandsToDelete.insert(command);
+        if (command->m_type > dynamic::CommandType::Unknown &&
+            command->m_type < dynamic::CommandType::ApplyCullMode &&
+            command->m_type != dynamic::CommandType::AllocateBuffer &&
+            command->m_type != dynamic::CommandType::ApplyBufferValue &&
+            command->m_type != dynamic::CommandType::ApplyBlitFramebuffer &&
+            command->m_type != dynamic::CommandType::ApplyBlending &&
+            command->m_type != dynamic::CommandType::ApplyRenderState &&
+            command->m_type != dynamic::CommandType::ApplyCullMode &&
+            command->m_type != dynamic::CommandType::ApplyDepthValue &&
+            command->m_type != dynamic::CommandType::ApplyValue) {
+            customMaterial->commandsToDelete.insert(command);
+        }
     }
 
     QQuick3DMaterial::updateSpatialNode(customMaterial);
diff --git a/src/quick3d/qquick3deffect.cpp b/src/quick3d/qquick3deffect.cpp
index 7b2681a32..af2208b03 100644
--- a/src/quick3d/qquick3deffect.cpp
+++ b/src/quick3d/qquick3deffect.cpp
@@ -389,18 +389,22 @@ QSSGRenderGraphObject *QQuick3DEffect::updateSpatialNode(QSSGRenderGraphObject *
 
     // We need to mark the commands that we allocated since they will need to be deallocted when the customMaterial is deleted.
     // We achieve this by filtering on the command type.
-    qDeleteAll(effectNode->commandsToDelete);
+    // Just redo the list without deleting it, or we end up calling already deleted commands in
+    // render if a shader variable changes
     effectNode->commandsToDelete.clear();
     for (auto command : effectNode->commands) {
-        if (command->m_type != dynamic::CommandType::AllocateBuffer &&
-                command->m_type != dynamic::CommandType::ApplyBufferValue &&
-                command->m_type != dynamic::CommandType::ApplyBlitFramebuffer &&
-                command->m_type != dynamic::CommandType::ApplyBlending &&
-                command->m_type != dynamic::CommandType::ApplyRenderState &&
-                command->m_type != dynamic::CommandType::ApplyCullMode &&
-                command->m_type != dynamic::CommandType::ApplyDepthValue &&
-                command->m_type != dynamic::CommandType::ApplyValue)
-        effectNode->commandsToDelete.insert(command);
+        if (command->m_type > dynamic::CommandType::Unknown &&
+            command->m_type < dynamic::CommandType::ApplyCullMode &&
+            command->m_type != dynamic::CommandType::AllocateBuffer &&
+            command->m_type != dynamic::CommandType::ApplyBufferValue &&
+            command->m_type != dynamic::CommandType::ApplyBlitFramebuffer &&
+            command->m_type != dynamic::CommandType::ApplyBlending &&
+            command->m_type != dynamic::CommandType::ApplyRenderState &&
+            command->m_type != dynamic::CommandType::ApplyCullMode &&
+            command->m_type != dynamic::CommandType::ApplyDepthValue &&
+            command->m_type != dynamic::CommandType::ApplyValue) {
+            effectNode->commandsToDelete.insert(command);
+        }
     }
 
     if (m_dirtyAttributes & Dirty::PropertyDirty) {
-- 
GitLab

openSUSE Build Service is sponsored by