Unreal.js-core icon indicating copy to clipboard operation
Unreal.js-core copied to clipboard

Incorrect JS return value when calling a C++ method that returns an enum

Open Deco opened this issue 5 years ago • 0 comments

In UnrealJS\Source\V8\Private\JavascriptIsolate_Private.cpp, in FJavascriptIsolateImplementation, in InternalReadProperty, in the else if(auto p = CastField<FEnumProperty>(Property)) branch, the following code is incorrect:

int32 Value = p->GetUnderlyingProperty()->GetValueTypeHash(Buffer);
return I.Keyword(p->GetEnum()->GetNameStringByIndex(Value));

Unlike the other branches, which call p->GetPropertyValue_InContainer(Buffer), this branch does not factor in the property's offset within the buffer (stored in Offset_Internal). This means it interprets whatever is at the head of the buffer as the property's value, resulting in incorrect return values in JS when calling a C++ method that returns an enum.

Locally, I'm using this and it seems to work:

int32 Value = p->GetUnderlyingProperty()->GetValueTypeHash(Buffer + p->GetOffset_ForInternal());
return I.Keyword(p->GetEnum()->GetNameStringByIndex(Value));

Deco avatar Aug 17 '20 06:08 Deco