From 29804a282192506a1aa66ff3b44bfea38fba5b68 Mon Sep 17 00:00:00 2001 From: Mark Tucker Date: Fri, 16 Feb 2024 23:25:25 -0500 Subject: [PATCH 1/2] Fix sizing of result array when calling GetScenePrimPaths with some invalid instance indices. We always need the result to be the size of the original request array, not the size of the number of valid entries in the array. This fixes crashes that could occur because the entries in the "instance index to result vector index" map expect the result entries to line up with the entries in the original request, and thus would operate past the end of the array. --- pxr/usdImaging/usdImaging/instanceAdapter.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pxr/usdImaging/usdImaging/instanceAdapter.cpp b/pxr/usdImaging/usdImaging/instanceAdapter.cpp index 1d6b49c949..6c9cb511be 100644 --- a/pxr/usdImaging/usdImaging/instanceAdapter.cpp +++ b/pxr/usdImaging/usdImaging/instanceAdapter.cpp @@ -2674,7 +2674,7 @@ UsdImagingInstanceAdapter::GetScenePrimPaths( } } - result.resize(validIndices); + result.resize(instanceIndices.size()); _GetScenePrimPathsFn primPathsFn( this, requestedIndicesMap, minIdx, result, proto.path); _RunForAllInstancesToDraw(instancerPrim, &primPathsFn); From 732fe3376074d1f0c533d98e26da1bbe8c98d273 Mon Sep 17 00:00:00 2001 From: Mark Tucker Date: Thu, 22 Feb 2024 13:55:23 -0500 Subject: [PATCH 2/2] Ensure the output result vector from GetScenePrimPaths is the same length as the input instanceIndices vector even if none of the instance indices are valid. This guarantee should ease the burden of error testing on callers of this method. --- pxr/usdImaging/usdImaging/instanceAdapter.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pxr/usdImaging/usdImaging/instanceAdapter.cpp b/pxr/usdImaging/usdImaging/instanceAdapter.cpp index 6c9cb511be..774bd57d9f 100644 --- a/pxr/usdImaging/usdImaging/instanceAdapter.cpp +++ b/pxr/usdImaging/usdImaging/instanceAdapter.cpp @@ -2654,6 +2654,10 @@ UsdImagingInstanceAdapter::GetScenePrimPaths( } } + // Ensure the result vector is the same size as instanceIndices + // even if there are no valid instance indices. + result.resize(instanceIndices.size()); + // at least one index was valid, get the prim paths if (validIndices > 0) { // For each valid requested index provide a mapping into the result vector @@ -2674,7 +2678,6 @@ UsdImagingInstanceAdapter::GetScenePrimPaths( } } - result.resize(instanceIndices.size()); _GetScenePrimPathsFn primPathsFn( this, requestedIndicesMap, minIdx, result, proto.path); _RunForAllInstancesToDraw(instancerPrim, &primPathsFn);