Files
UnrealEngineUWP/Engine/Source/Editor/PropertyEditor/Private/PropertyTextUtilities.cpp
jamie dale bb2eb686ca Fixed a crash when pasting into an array on class sparse data
This would try and get the value of the outer array property (for the inner array value) using FObjectBaseAddress::ObjectOrStruct as the start address, however for class sparse data FObjectBaseAddress::ObjectOrStruct was set to the CDO of the class that owns the sparse data, rather than the start of the sparse data itself. This resulted in a crash as it would try and read garbage from the CDO.

This change removes FObjectBaseAddress::ObjectOrStruct and FObjectBaseAddress::bIsStruct, in favor of storing FObjectBaseAddress::Object (if not editing a struct) and FObjectBaseAddress::StructAddress. FObjectBaseAddress::StructAddress always points to the thing that actually contains FObjectBaseAddress::BaseAddress, which allows the ImportText code to get the correct offset for the array property within the sparse data instance.

#jira
#rb Sebastian.Nordgren
#preflight 61a59b104f5d65edc3a8564b
#rnx

#ROBOMERGE-AUTHOR: jamie.dale
#ROBOMERGE-SOURCE: CL 18326295 via CL 18328452 via CL 18328534 via CL 18328607 via CL 18330452 via CL 18330516
#ROBOMERGE-BOT: STARSHIP (Release-Engine-Staging -> Release-Engine-Test) (v895-18170469)

[CL 18330630 by jamie dale in ue5-release-engine-test branch]
2021-11-30 15:35:13 -05:00

39 lines
1.8 KiB
C++

// Copyright Epic Games, Inc. All Rights Reserved.
#include "PropertyTextUtilities.h"
#include "PropertyNode.h"
#include "PropertyHandleImpl.h"
void FPropertyTextUtilities::PropertyToTextHelper(FString& OutString, const FPropertyNode* InPropertyNode, const FProperty* Property, const uint8* ValueAddress, UObject* Object, EPropertyPortFlags PortFlags)
{
if (InPropertyNode->GetArrayIndex() != INDEX_NONE || Property->ArrayDim == 1)
{
Property->ExportText_Direct(OutString, ValueAddress, ValueAddress, Object, PortFlags);
}
else
{
FArrayProperty::ExportTextInnerItem(OutString, Property, ValueAddress, Property->ArrayDim, ValueAddress, Property->ArrayDim, Object, PortFlags);
}
}
void FPropertyTextUtilities::PropertyToTextHelper(FString& OutString, const FPropertyNode* InPropertyNode, const FProperty* Property, const FObjectBaseAddress& ObjectAddress, EPropertyPortFlags PortFlags)
{
PropertyToTextHelper(OutString, InPropertyNode, Property, ObjectAddress.BaseAddress, ObjectAddress.Object, PortFlags);
}
void FPropertyTextUtilities::TextToPropertyHelper(const TCHAR* Buffer, const FPropertyNode* InPropertyNode, const FProperty* Property, uint8* ValueAddress, UObject* Object, EPropertyPortFlags PortFlags)
{
if (InPropertyNode->GetArrayIndex() != INDEX_NONE || Property->ArrayDim == 1)
{
Property->ImportText(Buffer, ValueAddress, PortFlags, Object);
}
else
{
FArrayProperty::ImportTextInnerItem(Buffer, Property, ValueAddress, PortFlags, Object);
}
}
void FPropertyTextUtilities::TextToPropertyHelper(const TCHAR* Buffer, const FPropertyNode* InPropertyNode, const FProperty* Property, const FObjectBaseAddress& ObjectAddress, EPropertyPortFlags PortFlags)
{
TextToPropertyHelper(Buffer, InPropertyNode, Property, ObjectAddress.BaseAddress, ObjectAddress.Object, PortFlags);
}