Skip to content

Commit

Permalink
[unreal]解决模板绑定对于const SomeClass &参数的默认值会读取到已经释放栈变量的问题,fix #1924
Browse files Browse the repository at this point in the history
  • Loading branch information
chexiongsheng committed Nov 21, 2024
1 parent a7e54c1 commit 283f45b
Showing 1 changed file with 45 additions and 1 deletion.
46 changes: 45 additions & 1 deletion unreal/Puerts/Source/JsEnv/Public/StaticCall.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,11 @@ struct FuncCallHelper<API, std::pair<Ret, std::tuple<Args...>>, CheckArguments,
return Arg;
}

void SetArgument(typename ArgumentType<T>::type InArg)
{
Arg = InArg;
}

void SetRef(typename API::ContextType context, typename API::ValueType holder)
{
}
Expand Down Expand Up @@ -418,6 +423,11 @@ struct FuncCallHelper<API, std::pair<Ret, std::tuple<Args...>>, CheckArguments,
return Arg;
}

void SetArgument(typename ArgumentType<T>::type InArg)
{
Arg = InArg;
}

void SetRef(typename API::ContextType context, typename API::ValueType holder)
{
if (&Buf != &(Arg.get()))
Expand Down Expand Up @@ -452,6 +462,11 @@ struct FuncCallHelper<API, std::pair<Ret, std::tuple<Args...>>, CheckArguments,
return Arg;
}

void SetArgument(typename ArgumentType<T>::type InArg)
{
Arg = InArg;
}

void SetRef(typename API::ContextType context, typename API::ValueType holder)
{
}
Expand All @@ -476,6 +491,15 @@ struct FuncCallHelper<API, std::pair<Ret, std::tuple<Args...>>, CheckArguments,
return Arg;
}

using BuffType = typename std::remove_const<typename std::remove_reference<T>::type>::type;
BuffType Buf;

void SetArgument(BuffType InArg)
{
Buf = InArg;
Arg = Buf;
}

void SetRef(typename API::ContextType context, typename API::ValueType holder)
{
}
Expand All @@ -501,6 +525,11 @@ struct FuncCallHelper<API, std::pair<Ret, std::tuple<Args...>>, CheckArguments,
return Arg;
}

void SetArgument(typename ArgumentType<T>::type InArg)
{
Arg = InArg;
}

void SetRef(typename API::ContextType context, typename API::ValueType holder)
{
API::UpdateRefValue(context, holder, API::template Converter<typename std::decay<T>::type>::toScript(context, Arg));
Expand All @@ -527,6 +556,11 @@ struct FuncCallHelper<API, std::pair<Ret, std::tuple<Args...>>, CheckArguments,
return Arg ? Arg : &Buf;
}

void SetArgument(BuffType InArg)
{
Buf = InArg;
}

void SetRef(typename API::ContextType context, typename API::ValueType holder)
{
API::UpdateRefValue(context, holder, API::template Converter<BuffType>::toScript(context, Buf));
Expand All @@ -551,6 +585,11 @@ struct FuncCallHelper<API, std::pair<Ret, std::tuple<Args...>>, CheckArguments,
return Arg;
}

void SetArgument(T InArg)
{
Arg = InArg;
}

void SetRef(typename API::ContextType context, typename API::ValueType holder)
{
}
Expand All @@ -574,6 +613,11 @@ struct FuncCallHelper<API, std::pair<Ret, std::tuple<Args...>>, CheckArguments,
return Arg;
}

void SetArgument(typename ArgumentType<T>::type InArg)
{
Arg = InArg;
}

void SetRef(typename API::ContextType context, typename API::ValueType holder)
{
}
Expand Down Expand Up @@ -615,7 +659,7 @@ struct FuncCallHelper<API, std::pair<Ret, std::tuple<Args...>>, CheckArguments,
{
if (argCount <= Pos)
{
std::get<Pos>(cppArgHolders).Arg = defaultValue;
std::get<Pos>(cppArgHolders).SetArgument(defaultValue);
}
DefaultValueSetter<0, Pos + 1, FullArgs...>::Set(cppArgHolders, argCount, rest...);
}
Expand Down

0 comments on commit 283f45b

Please sign in to comment.