[Unity] Bug: 在xil2cpp下在js获取raycast会报错
前置阅读 | Pre-reading
Puer的版本 | Puer Version
2.0.0.pre5
Unity的版本 | Unity Version
2022.3.0
发生在哪个平台 | Platform
Windows Standalone
错误信息 | Error Message
const hitInfo = puer.$ref();
CS.UnityEngine.Physics.Raycast(originPos, CS.UnityEngine.Vector3.down, hitInfo);
在il2cpp打包下会报错
问题重现 | Bug reproduce
新建个空包执行脚本 const hitInfo = puer.$ref(); CS.UnityEngine.Physics.Raycast(originPos, CS.UnityEngine.Vector3.down, hitInfo); 打出il2cpp windows 包
https://github.com/Tencent/puerts/commit/fdd260b9c8b14aeba7ea0dbe284d6e7ccbb23dc5 看看是不是这个修的问题。
另外你截图的JS栈是drawDots,在往上也没有出现Raycast,有没有可能不是Raycast产生的问题
换成最新版了 还是一样,drawdots里面调用了raycast
感觉有俩个问题
- new CS.UnityEngine.RaycastHit() 确实是无法创建(但好像不需要去new CS.UnityEngine.RaycastHit)
- 上面代码 报错报在这个地方
这个ContactEventDelegate是怎么触发的?看上去RayCast不会用到 我测试了一下RayCast也没事(返回false)
jsEnv = new JsEnv();
RaycastHit rh;
UnityEngine.Physics.Raycast(
new UnityEngine.Vector3(0, 0, 0),
UnityEngine.Vector3.down,
out rh
);
jsEnv.Eval(@"
const hitInfo = puer.$ref(null);
console.log(CS.UnityEngine.Physics.Raycast(
new CS.UnityEngine.Vector3(0, 0, 0),
CS.UnityEngine.Vector3.down,
hitInfo
))
");
这段代码打windows il2cpp 包运行 我直接就报错啊,难道是2022的问题? TestRaycast.zip
这个ContactEventDelegate 貌似2022.2以上才有这个东西
try load type throw System.Exception: create TypeInfo for UnityEngine.Physics+ContactEventDelegate fail. maybe the BridgeInfo is not found, try to regenerate the FunctionBridge.Gen.h
at Puerts.TypeMapping.TypeRegister.Register (System.Type type, System.Reflection.MethodBase[] ctors, System.Reflection.MethodBase[] methods, System.Reflection.PropertyInfo[] properties, System.Reflection.FieldInfo[] fields, System.Boolean throwIfMemberFail) [0x00000] in <00000000000000000000000000000000>:0
at Puerts.TypeMapping.TypeRegister.RegisterNoThrow (System.IntPtr typeId, System.Boolean includeNonPublic) [0x00000] in <00000000000000000000000000000000>:0
at PuertsTest.JsCallCs.Start () [0x00000] in <00000000000000000000000000000000>:0
Puerts.TypeMapping.TypeRegister:RegisterNoThrow(IntPtr, Boolean)
PuertsTest.JsCallCs:Start()
InvalidOperationException: puerts/init_il2cpp.mjs:25: TypeError: Cannot set properties of undefined (setting '__p_innerType')
TypeError: Cannot set properties of undefined (setting '__p_innerType')
at Object.puer.loadType (puerts/init_il2cpp.mjs:25:27)
at csTypeToClass (puerts/csharp.mjs:12:20)
at csTypeToClass (puerts/csharp.mjs:70:39)
at Object.get (puerts/csharp.mjs:92:31)
at chunk:3:44
at PuertsTest.JsCallCs.Start () [0x00000] in <00000000000000000000000000000000>:0
复现这样的错误,我看看
ContactEventDelegate所用到的NativeArray<ContactPairHeader>.ReadOnly在Runtime和Editor下获得的字段不同,Runtime下没有m_Safety属性
是要写个filter吗?
https://github.com/Tencent/puerts/blob/master/unity/Assets/core/upm/Runtime/Resources/puerts/csharp.mjs#L61 目前发现是这里触发的,GetNestType时触发了RegisterType。这条链路还没法被Filter过滤。快捷点的话只能先在这里手动if过滤一下