Fix memory leak when passing object instead of array
@@ -727,12 +727,14 @@ RED4ext::CStackType Scripting::ToRED(sol::object aObject, RED4ext::IRTTIType* ap
}
}
else if (apRttiType->GetType() == RED4ext::ERTTIType::Array)
+ {
+ if (!hasData || aObject.get_type() == sol::type::table)
{
auto* pArrayType = static_cast<RED4ext::CArray*>(apRttiType);
const auto pMemory = static_cast<RED4ext::DynArray<void*>*>(apAllocator->Allocate(apRttiType->GetSize()));
apRttiType->Init(pMemory);
- if (hasData && aObject.is<sol::table>())
+ if (hasData)
{
auto* pArrayInnerType = pArrayType->GetInnerType();
@@ -749,6 +751,7 @@ RED4ext::CStackType Scripting::ToRED(sol::object aObject, RED4ext::IRTTIType* ap
result.value = pMemory;
}
+ }
else if (apRttiType->GetType() == RED4ext::ERTTIType::ScriptReference)
{
if (aObject.is<ClassReference>())
