From 8e2d02dc2bd389cb9b4450c9a895cf3a1cb7fc13 Mon Sep 17 00:00:00 2001 From: Volker Enderlein Date: Tue, 23 Jun 2020 16:45:03 +0200 Subject: Fix boundingVolumePositionAttribute handling This patch fixes a crash when using setBoundingVolumePositionAttribute on geometries with indexBuffer. Fixes: QTBUG-85131 Change-Id: Ib5d5e71412daf3b032fc85105cab858c3a937174 Reviewed-by: Mike Krus (cherry picked from commit 449d4bcf18f723c70f3f040df49573360d9017a0) Reviewed-by: Volker Enderlein --- src/render/jobs/calcboundingvolumejob.cpp | 58 +++++++++++++++++-------------- 1 file changed, 31 insertions(+), 27 deletions(-) diff --git a/src/render/jobs/calcboundingvolumejob.cpp b/src/render/jobs/calcboundingvolumejob.cpp index 842b301c9..dc58eb6b9 100644 --- a/src/render/jobs/calcboundingvolumejob.cpp +++ b/src/render/jobs/calcboundingvolumejob.cpp @@ -241,9 +241,10 @@ BoundingVolumeComputeData findBoundingVolumeComputeData(NodeManagers *manager, E int drawVertexCount = gRenderer->vertexCount(); // may be 0, gets changed below if so Qt3DRender::Render::Attribute *positionAttribute = manager->lookupResource(geom->boundingPositionAttribute()); + bool hasBoundingVolumePositionAttribute = positionAttribute != nullptr; // Use the default position attribute if attribute is null - if (!positionAttribute) { + if (!hasBoundingVolumePositionAttribute) { const auto attrIds = geom->attributes(); for (const Qt3DCore::QNodeId &attrId : attrIds) { positionAttribute = manager->lookupResource(attrId); @@ -271,37 +272,40 @@ BoundingVolumeComputeData findBoundingVolumeComputeData(NodeManagers *manager, E // Check if there is an index attribute. Qt3DRender::Render::Attribute *indexAttribute = nullptr; Buffer *indexBuf = nullptr; - const QVector attributes = geom->attributes(); - - for (Qt3DCore::QNodeId attrNodeId : attributes) { - Qt3DRender::Render::Attribute *attr = manager->lookupResource(attrNodeId); - if (attr && attr->attributeType() == QAttribute::IndexAttribute) { - indexBuf = manager->lookupResource(attr->bufferId()); - if (indexBuf) { - indexAttribute = attr; - - if (!drawVertexCount) - drawVertexCount = indexAttribute->count(); - - const QAttribute::VertexBaseType validIndexTypes[] = { - QAttribute::UnsignedShort, - QAttribute::UnsignedInt, - QAttribute::UnsignedByte - }; - - if (std::find(std::begin(validIndexTypes), - std::end(validIndexTypes), - indexAttribute->vertexBaseType()) == std::end(validIndexTypes)) { - qWarning() << "findBoundingVolumeComputeData: Unsupported index attribute type" << indexAttribute->name() << indexAttribute->vertexBaseType(); - return {}; - } - break; + if (!hasBoundingVolumePositionAttribute) { + const QVector attributes = geom->attributes(); + + for (Qt3DCore::QNodeId attrNodeId : attributes) { + Qt3DRender::Render::Attribute *attr = manager->lookupResource(attrNodeId); + if (attr && attr->attributeType() == QAttribute::IndexAttribute) { + indexBuf = manager->lookupResource(attr->bufferId()); + if (indexBuf) { + indexAttribute = attr; + + if (!drawVertexCount) + drawVertexCount = indexAttribute->count(); + + const QAttribute::VertexBaseType validIndexTypes[] = { + QAttribute::UnsignedShort, + QAttribute::UnsignedInt, + QAttribute::UnsignedByte + }; + + if (std::find(std::begin(validIndexTypes), + std::end(validIndexTypes), + indexAttribute->vertexBaseType()) == std::end(validIndexTypes)) { + qWarning() << "findBoundingVolumeComputeData: Unsupported index attribute type" << indexAttribute->name() << indexAttribute->vertexBaseType(); + return {}; + } + + break; + } } } } - if (!indexAttribute && !drawVertexCount) + if (hasBoundingVolumePositionAttribute || (!indexAttribute && !drawVertexCount)) drawVertexCount = positionAttribute->count(); // Buf will be set to not dirty once it's loaded -- cgit v1.2.1