Skip to content

Commit

Permalink
Fixed a bug in sdr where int arrays would always default to zero.
Browse files Browse the repository at this point in the history
(Internal change: 2352232)
  • Loading branch information
pellerington authored and pixar-oss committed Dec 19, 2024
1 parent 337aeff commit e7e9712
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions pxr/usd/sdr/shaderProperty.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,44 @@ namespace {
}
}

// INT ARRAY (FIXED SIZE 2, 3, 4)
// ---------------------------------------------------------------------
else if (sdrType == SdrPropertyTypes->Int &&
isArray) {
VtIntArray arrayVal;
_GetValue(sdrDefaultValue, &arrayVal);

if (arrayVal.size() != arraySize) {
TF_DEBUG(SDR_TYPE_CONFORMANCE).Msg(
"Default value for fixed size int array type does not "
"have the right length (%zu vs expected %zu)",
arrayVal.size(), arraySize);
return sdrDefaultValue;
}

// We return a fixed-size array for arrays with size 2, 3, or 4
// because SdrShaderProperty::GetTypeAsSdfType returns a specific
// size type (Int2, Int3, Int4). If in the future we want to
// return a VtIntArray instead, we need to change the logic in
// SdrShaderProperty::GetTypeAsSdfType
if (arraySize == 2) {
return VtValue(
GfVec2i(arrayVal[0],
arrayVal[1]));
} else if (arraySize == 3) {
return VtValue(
GfVec3i(arrayVal[0],
arrayVal[1],
arrayVal[2]));
} else if (arraySize == 4) {
return VtValue(
GfVec4i(arrayVal[0],
arrayVal[1],
arrayVal[2],
arrayVal[3]));
}
}

// Default value's type was not conformant, but no special translation
// step was found. So we use the default value of the SdfTypeName, which
// is guaranteed to match
Expand Down

0 comments on commit e7e9712

Please sign in to comment.