From 00cc67f1eac391882a4b1789e27f3e6ce5cdee8d Mon Sep 17 00:00:00 2001 From: Santeri Puranen <26481940+santeripuranen@users.noreply.github.com> Date: Thu, 14 Mar 2024 08:23:07 +0200 Subject: [PATCH] Correction to index buffer type in loadMeshBVH Only unsigned integer types are supported for user-supplied meshes in QQuick3DGeometry, and make sense for index buffers in general. The pre-set signed indexBufferFormat was always used in the old code, since "attribute.componentType" (either uint32 or uint16) never matched any of the signed alternatives in the if-clauses. This appears to have worked fine with uint32 buffers, but caused crashes with uint16 (due to out-of-bounds accesses caused by bad casts downstream). --- .../resourcemanager/qssgrenderbuffermanager.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/runtimerender/resourcemanager/qssgrenderbuffermanager.cpp b/src/runtimerender/resourcemanager/qssgrenderbuffermanager.cpp index fcbbfff32..840bb2a43 100644 --- a/src/runtimerender/resourcemanager/qssgrenderbuffermanager.cpp +++ b/src/runtimerender/resourcemanager/qssgrenderbuffermanager.cpp @@ -1778,7 +1778,7 @@ std::unique_ptr QSSGBufferManager::loadMeshBVH(QSSGRenderGeometry * // Build BVH bool hasIndexBuffer = false; - QSSGRenderComponentType indexBufferFormat = QSSGRenderComponentType::Int32; + QSSGRenderComponentType indexBufferFormat = QSSGRenderComponentType::UnsignedInt32; bool hasUV = false; int uvOffset = -1; int posOffset = -1; @@ -1795,10 +1795,10 @@ std::unique_ptr QSSGBufferManager::loadMeshBVH(QSSGRenderGeometry * uvOffset = attribute.offset; } else if (attribute.semantic == QSSGMesh::RuntimeMeshData::Attribute::IndexSemantic) { hasIndexBuffer = true; - if (attribute.componentType == QSSGMesh::Mesh::ComponentType::Int16) - indexBufferFormat = QSSGRenderComponentType::Int16; - else if (attribute.componentType == QSSGMesh::Mesh::ComponentType::Int32) - indexBufferFormat = QSSGRenderComponentType::Int32; + if (attribute.componentType == QSSGMesh::Mesh::ComponentType::UnsignedInt16) + indexBufferFormat = QSSGRenderComponentType::UnsignedInt16; + else if (attribute.componentType == QSSGMesh::Mesh::ComponentType::UnsignedInt32) + indexBufferFormat = QSSGRenderComponentType::UnsignedInt32; } }