Fix unpacking Variant structure if input value is a scalar

#2163
This commit is contained in:
Wojtek Figat
2024-01-10 12:08:01 +01:00
parent d807e9bfe0
commit b7cc4c768f
2 changed files with 25 additions and 1 deletions

View File

@@ -685,9 +685,9 @@ void VisjectExecutor::ProcessGroupPacking(Box* box, Node* node, Value& value)
case 36:
{
// Get value with structure data
Variant structureValue = eatBox(node, node->GetBox(0)->FirstConnection());
if (!node->GetBox(0)->HasConnection())
return;
Variant structureValue = eatBox(node, node->GetBox(0)->FirstConnection());
// Find type
const StringView typeName(node->Values[0]);
@@ -741,6 +741,12 @@ void VisjectExecutor::ProcessGroupPacking(Box* box, Node* node, Value& value)
return;
}
const ScriptingType& type = typeHandle.GetType();
if (structureValue.Type.Type != VariantType::Structure) // If structureValue is eg. Float we can try to cast it to a required structure type
{
VariantType typeVariantType(typeNameAnsiView);
if (Variant::CanCast(structureValue, typeVariantType))
structureValue = Variant::Cast(structureValue, typeVariantType);
}
structureValue.InvertInline(); // Extract any Float3/Int32 into Structure type from inlined format
const ScriptingTypeHandle structureValueTypeHandle = Scripting::FindScriptingType(structureValue.Type.GetTypeName());
if (structureValue.Type.Type != VariantType::Structure || typeHandle != structureValueTypeHandle)