diff options
author | Volker Enderlein <volker.enderlein@ifm-chemnitz.de> | 2020-06-23 16:45:03 +0200 |
---|---|---|
committer | Volker Enderlein <volker.enderlein@ifm-chemnitz.de> | 2020-06-26 21:04:08 +0200 |
commit | 8e2d02dc2bd389cb9b4450c9a895cf3a1cb7fc13 (patch) | |
tree | f916f18c4547a4d83a016602006939eb2a91ec37 | |
parent | 5f83aa911364925d93c552c4bbea885a4e2807ee (diff) | |
download | qt3d-8e2d02dc2bd389cb9b4450c9a895cf3a1cb7fc13.tar.gz |
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 <mike.krus@kdab.com>
(cherry picked from commit 449d4bcf18f723c70f3f040df49573360d9017a0)
Reviewed-by: Volker Enderlein <volker.enderlein@ifm-chemnitz.de>
-rw-r--r-- | src/render/jobs/calcboundingvolumejob.cpp | 58 |
1 files 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<Attribute, AttributeManager>(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<Attribute, AttributeManager>(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<Qt3DCore::QNodeId> attributes = geom->attributes(); - - for (Qt3DCore::QNodeId attrNodeId : attributes) { - Qt3DRender::Render::Attribute *attr = manager->lookupResource<Attribute, AttributeManager>(attrNodeId); - if (attr && attr->attributeType() == QAttribute::IndexAttribute) { - indexBuf = manager->lookupResource<Buffer, BufferManager>(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<Qt3DCore::QNodeId> attributes = geom->attributes(); + + for (Qt3DCore::QNodeId attrNodeId : attributes) { + Qt3DRender::Render::Attribute *attr = manager->lookupResource<Attribute, AttributeManager>(attrNodeId); + if (attr && attr->attributeType() == QAttribute::IndexAttribute) { + indexBuf = manager->lookupResource<Buffer, BufferManager>(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 |