From 6e915055577c2d931b51e9fd025f193c3f58bbb3 Mon Sep 17 00:00:00 2001 From: cpichard Date: Tue, 11 Jun 2024 14:15:03 +0100 Subject: [PATCH] check if the VtValue is empty before doing a UncheckedGet (#1934) --- CHANGELOG.md | 1 + libs/render_delegate/mesh.cpp | 14 ++++++++------ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bcc8c707c..608cbe231 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ - [usd#1923](https://github.com/Autodesk/arnold-usd/issues/1923) - Fix instance primvar indices with multiple prototypes - [usd#1929](https://github.com/Autodesk/arnold-usd/issues/1929) - Ensure subdiv_iterations is not set uselessly during procedural updates +- [usd#1932](https://github.com/Autodesk/arnold-usd/issues/1932) - Fix a crash when the number of elements in a primvar should be equal to the number of points but is not. ## [7.3.2.0] - 2024-05-22 diff --git a/libs/render_delegate/mesh.cpp b/libs/render_delegate/mesh.cpp index e881c094e..3a8552dba 100644 --- a/libs/render_delegate/mesh.cpp +++ b/libs/render_delegate/mesh.cpp @@ -104,14 +104,16 @@ struct _ConvertValueToArnoldParameter>()) { return; } - const VtArray *v0 = nullptr; if (requiredValues) { for (const auto& value : samples.values) { - const auto& array = value.UncheckedGet>(); - if (array.size() == *requiredValues) { - v0 = &array; - break; + // Looking for the correct buffer by size. + if (!value.IsEmpty()) { + const auto& array = value.UncheckedGet>(); + if (array.size() == *requiredValues) { + v0 = &array; + break; + } } } } @@ -442,8 +444,8 @@ void HdArnoldMesh::Sync( } else if (primvar.first == HdTokens->normals) { if (desc.value.IsEmpty()) { HdArnoldIndexedSampledPrimvarType sample; - sceneDelegate->SampleIndexedPrimvar(id, primvar.first, &sample); sample.count = _numberOfPositionKeys; + sceneDelegate->SampleIndexedPrimvar(id, primvar.first, &sample); _ConvertFaceVaryingPrimvarToBuiltin( GetArnoldNode(), sample, sample.indices.empty() ? VtIntArray{} : sample.indices[0], str::nlist, str::nidxs, &_vertexCounts, &_vertexCountSum);