Skip to content

Commit

Permalink
[unity] fix blittablecopy bug
Browse files Browse the repository at this point in the history
  • Loading branch information
zombieyang committed Jul 1, 2023
1 parent d074c15 commit 7ffb2f4
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ namespace PuertsStaticWrap
{
return new RegisterInfo
{
#if !EXPERIMENTAL_IL2CPP_PUERTS || !ENABLE_IL2CPP
BlittableCopy = ${item.BlittableCopy},
#endif
Members = new System.Collections.Generic.Dictionary<string, MemberRegisterInfo>
{
${FOR(listToJsArray(item.Members), member=> `
Expand All @@ -46,6 +43,7 @@ namespace PuertsStaticWrap
{
${FOR(typeRegisterInfos, item => `
jsEnv.AddRegisterInfoGetter(typeof(${CS.Puerts.TypeExtensions.GetFriendlyName(item.Type)}), GetRegisterInfo_${item.WrapperName});
${item.BlittableCopy ? item.WrapperName + ".InitBlittableCopy(jsEnv);": ""}
`)}
}
}
Expand Down
9 changes: 8 additions & 1 deletion unity/Assets/core/upm/Editor/Src/Generator/FileExporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ public static void GenRegisterInfo(string outDir, ILoader loader = null)
{
var configure = Puerts.Configure.GetConfigureByTags(new List<string>() {
"Puerts.BindingAttribute",
"Puerts.BlittableCopyAttribute",
});
var genTypes = configure["Puerts.BindingAttribute"].Select(kv => kv.Key)
.Where(o => o is Type)
Expand All @@ -163,12 +164,18 @@ public static void GenRegisterInfo(string outDir, ILoader loader = null)
.Distinct()
.ToList();

var blittableCopyTypes = new HashSet<Type>(configure["Puerts.BlittableCopyAttribute"].Select(kv => kv.Key)
.Where(o => o is Type)
.Cast<Type>()
.Where(t => !t.IsPrimitive && Utils.isBlittableType(t))
.Distinct());

if (!Utils.HasFilter)
{
Utils.SetFilters(Configure.GetFilters());
}

var RegisterInfos = RegisterInfoGenerator.GetRegisterInfos(genTypes);
var RegisterInfos = RegisterInfoGenerator.GetRegisterInfos(genTypes, blittableCopyTypes);

if (loader == null)
{
Expand Down
4 changes: 3 additions & 1 deletion unity/Assets/core/upm/Editor/Src/Generator/RegisterInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ internal List<MemberRegisterInfoForGenerate> GetAllMember()
}
}

public static List<RegisterInfoForGenerate> GetRegisterInfos(List<Type> genTypes)
public static List<RegisterInfoForGenerate> GetRegisterInfos(List<Type> genTypes, HashSet<Type> blittableCopyTypes)
{
BindingFlags flag = BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public;

Expand Down Expand Up @@ -255,6 +255,8 @@ public static List<RegisterInfoForGenerate> GetRegisterInfos(List<Type> genTypes
{
WrapperName = Utils.GetWrapTypeName(type),
BlittableCopy = blittableCopyTypes.Contains(type),
Type = type,
Members = Collector.GetAllMember(),
Expand Down
4 changes: 2 additions & 2 deletions unity/native_src/Src/JSEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -446,8 +446,7 @@ namespace puerts
{
if (LifeCycleInfo->Constructor) Ptr = LifeCycleInfo->Constructor(Isolate, Info, Info.Length(), LifeCycleInfo->Data);
}
if (Ptr != nullptr)
FV8Utils::IsolateData<JSEngine>(Isolate)->BindObject(LifeCycleInfo, Ptr, Self);
FV8Utils::IsolateData<JSEngine>(Isolate)->BindObject(LifeCycleInfo, Ptr, Self);
}
else
{
Expand Down Expand Up @@ -622,6 +621,7 @@ namespace puerts
{
JSObject->SetAlignedPointerInInternalField(0, Ptr);
}
if (Ptr == nullptr) return;

JSObject->SetAlignedPointerInInternalField(1, LifeCycleInfo);
JSObject->SetAlignedPointerInInternalField(2, reinterpret_cast<void *>(OBJECT_MAGIC));
Expand Down

0 comments on commit 7ffb2f4

Please sign in to comment.