Skip to content

Commit

Permalink
bug fix for duplicating delegate signature which has out parameters.
Browse files Browse the repository at this point in the history
  • Loading branch information
rowechien committed Mar 28, 2020
1 parent ef6f9a2 commit da2f06e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
7 changes: 3 additions & 4 deletions Plugins/UnLua/Source/UnLua/Private/DelegateHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -510,11 +510,10 @@ void FDelegateHelper::CreateSignature(UFunction *TemplateFunction, FName FuncNam
// set custom thunk function for the duplicated UFunction
OverrideUFunction(SignatureFunction, (FNativeFuncPtr)&FDelegateHelper::ProcessDelegate, SignatureDesc, false);

uint8 NumOutProperties = SignatureDesc->SignatureFunctionDesc->GetNumOutProperties();
uint8 NumNonConstRefProperties = SignatureDesc->SignatureFunctionDesc->HasReturnProperty() ? NumOutProperties - 1 : NumOutProperties;
if (NumNonConstRefProperties > 0)
uint8 NumRefProperties = SignatureDesc->SignatureFunctionDesc->GetNumRefProperties();
if (NumRefProperties > 0)
{
SignatureFunction->FunctionFlags |= FUNC_HasOutParms; // 'FUNC_HasOutParms' will not be set for signature function even if it has non-const reference parameters
SignatureFunction->FunctionFlags |= FUNC_HasOutParms; // 'FUNC_HasOutParms' will not be set for signature function even if it has out parameters
}

Callbacks.Add(Callback, SignatureFunction);
Expand Down
5 changes: 4 additions & 1 deletion Plugins/UnLua/Source/UnLua/Private/UEReflectionUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -936,7 +936,8 @@ FPropertyDesc* FPropertyDesc::Create(UProperty *InProperty)
* Function descriptor constructor
*/
FFunctionDesc::FFunctionDesc(UFunction *InFunction, FParameterCollection *InDefaultParams, int32 InFunctionRef)
: Function(InFunction), DefaultParams(InDefaultParams), ReturnPropertyIndex(INDEX_NONE), LatentPropertyIndex(INDEX_NONE), FunctionRef(InFunctionRef), bStaticFunc(false), bInterfaceFunc(false)
: Function(InFunction), DefaultParams(InDefaultParams), ReturnPropertyIndex(INDEX_NONE), LatentPropertyIndex(INDEX_NONE)
, FunctionRef(InFunctionRef), NumRefProperties(0), bStaticFunc(false), bInterfaceFunc(false)
{
check(InFunction);

Expand Down Expand Up @@ -985,6 +986,8 @@ FFunctionDesc::FFunctionDesc(UFunction *InFunction, FParameterCollection *InDefa
}
else if (Property->HasAnyPropertyFlags(CPF_OutParm))
{
++NumRefProperties;

// pre-create OutParmRec for 'out' property
#if !SUPPORTS_RPC_CALL
FOutParmRec *Out = (FOutParmRec*)FMemory::Malloc(sizeof(FOutParmRec), alignof(FOutParmRec));
Expand Down
19 changes: 17 additions & 2 deletions Plugins/UnLua/Source/UnLua/Private/UEReflectionUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,9 @@ class FFunctionDesc
FORCEINLINE bool IsValid() const { return Function != nullptr; }

/**
* Test if this function has return parameter
* Test if this function has return property
*
* @return - true if the function has return parameter, false otherwise
* @return - true if the function has return property, false otherwise
*/
FORCEINLINE bool HasReturnProperty() const { return ReturnPropertyIndex > INDEX_NONE; }

Expand All @@ -236,6 +236,20 @@ class FFunctionDesc
*/
FORCEINLINE uint8 GetNumOutProperties() const { return ReturnPropertyIndex > INDEX_NONE ? OutPropertyIndices.Num() + 1 : OutPropertyIndices.Num(); }

/**
* Get the number of reference properties
*
* @return - the number of reference properties.
*/
FORCEINLINE uint8 GetNumRefProperties() const { return NumRefProperties; }

/**
* Get the number of non-const reference properties
*
* @return - the number of non-const reference properties.
*/
FORCEINLINE uint8 GetNumNoConstRefProperties() const { return OutPropertyIndices.Num(); }

/**
* Get the 'true' function
*
Expand Down Expand Up @@ -302,6 +316,7 @@ class FFunctionDesc
int32 ReturnPropertyIndex;
int32 LatentPropertyIndex;
int32 FunctionRef;
uint8 NumRefProperties;
bool bStaticFunc;
bool bInterfaceFunc;
};
Expand Down

0 comments on commit da2f06e

Please sign in to comment.