throw-out / puerts-unity-kit

使用typescript开始你的unity项目(基于puerts的项目模板). 在ts中使用Unity生命周期方法丶绑定ts脚本并序列化其成员丶在ts中使用多线程实例等功能.
Other
46 stars 8 forks source link

Report TypeError when running webgl application #17

Open Another-Ghost opened 1 week ago

Another-Ghost commented 1 week ago

BuildTestWebGL.framework.js.gz:10 Exception: TypeError: Cannot read properties of undefined (reading 'apply') at NativeObject.GetComponents (http://localhost:62260/puerts_browser_js_resources.js:14039:23) at new TsBehaviourConstructor (http://localhost:62260/puerts_browser_js_resources.js:13332:39) at new showCard (http://localhost:62260/puerts_browser_js_resources.js:12889:5) at JSFunction.init [as _func] (http://localhost:62260/puerts_browser_js_resources.js:12948:10) at JSFunction.invoke (http://localhost:62260/puerts-runtime.js:205:27) at InvokeJSFunction (http://localhost:62260/puerts-runtime.js:1390:58) at _InvokeJSFunction (http://localhost:62260/Build/BuildTestWebGL.framework.js.gz:10:35860) at http://localhost:62260/Build/BuildTestWebGL.wasm.gz:wasm-function[60840]:0x10141da at http://localhost:62260/Build/BuildTestWebGL.wasm.gz:wasm-function[22166]:0x6e8ec9 at http://localhost:62260/Build/BuildTestWebGL.wasm.gz:wasm-function[77183]:0x13ba890 at http://localhost:62260/Build/BuildTestWebGL.wasm.gz:wasm-function[83219]:0x147ffd5 at http://localhost:62260/Build/BuildTestWebGL.wasm.gz:wasm-function[87038]:0x14dfad7 at http://localhost:62260/Build/BuildTestWebGL.wasm.gz:wasm-function[106260]:0x1ddf81b at invoke_iiii (http://localhost:62260/Build/BuildTestWebGL.framework.js.gz:10:438468) at http://localhost:62260/Build/BuildTestWebGL.wasm.gz:wasm-function[87022]:0x14deb71 at http://localhost:62260/Build/BuildTestWebGL.wasm.gz:wasm-function[1072]:0xe5f96 at http://localhost:62260/Build/BuildTestWebGL.wasm.gz:wasm-function[105490]:0x1d9414e at http://localhost:62260/Build/BuildTestWebGL.wasm.gz:wasm-function[102438]:0x1d18b44 at http://localhost:62260/Build/BuildTestWebGL.wasm.gz:wasm-function[88229]:0x1568c2b at http://localhost:62260/Build/BuildTestWebGL.wasm.gz:wasm-function[88243]:0x156a272 at http://localhost:62260/Build/BuildTestWebGL.wasm.gz:wasm-function[101975]:0x1cf3376 at http://localhost:62260/Build/BuildTestWebGL.wasm.gz:wasm-function[100846]:0x1c6c83b at http://localhost:62260/Build/BuildTestWebGL.wasm.gz:wasm-function[100785]:0x1c631d0 at http://localhost:62260/Build/BuildTestWebGL.wasm.gz:wasm-function[100785]:0x1c63243 at http://localhost:62260/Build/BuildTestWebGL.wasm.gz:wasm-function[106235]:0x1dc5caa at http://localhost:62260/Build/BuildTestWebGL.wasm.gz:wasm-function[106265]:0x1ddf857 at browserIterationFunc (http://localhost:62260/Build/BuildTestWebGL.framework.js.gz:10:248128) at callUserCallback (http://localhost:62260/Build/BuildTestWebGL.framework.js.gz:10:201750) at Object.runIter (http://localhost:62260/Build/BuildTestWebGL.framework.js.gz:10:202990) at Browser_mainLoop_runner (http://localhost:62260/Build/BuildTestWebGL.framework.js.gz:10:201286) at Puerts.GenericDelegate.Action[T1] (T1 p1) [0x00000] in <00000000000000000000000000000000>:0

image I built this by following the https://github.com/zombieyang/puerts_unity_webgl_demo 's instruction and click Publish-WebGL too.

throw-out commented 1 week ago

Could you please provide the code for line 14039 of the puerts_browser_js_resources.js file

throw-out commented 1 week ago

Awake, Start, OnEnable methods are called in the base class xor.TsBehaviour, so stack information is needed to determine the problem


基类xor.TsBehaviour中会调用Awake丶Start丶OnEnable方法, 因此需要堆栈信息来确定问题

throw-out commented 1 week ago

Does it work well in UnityEditor mode

Another-Ghost commented 1 week ago

image And Yes, it works in Editor.

throw-out commented 1 week ago

It looks like the error occurs here, but I'm not sure how it appears at the moment (the error only occurs on the WebGL platform). Could you provide a minimal reproducible demo or the WebGL build image

throw-out commented 1 week ago

The WebGL build uses IL2CPP, and it is possible that the code has stripped the GameObject.GetComponents method.

throw-out commented 1 week ago

Please try disabling stripping or set the stripping level to 'Low' and then rebuild.

throw-out commented 1 week ago

Please try disabling stripping or set the stripping level to 'Low' and then rebuild.

At the same time, you might need to use link.xml.

Another-Ghost commented 1 week ago

请问我该怎么发给你,我把 stripping level 降到最低了还是不行 image 又有新的错误,感觉即使用 link.xml 也得添加很多

throw-out commented 1 week ago

webgl平台强制IL2CPP打包, 一般有两种常见配置来防止代码裁剪:

  1. 执行Tools/PuerTS/Generte Code生成静态代码(跨语言性能会更好但webgl不推荐, 会非常显著得增大wasm包体积和其内存占用)
  2. 配置link.xml文件(可以使用[这里]的工具分析typescript代码)

建议将裁剪等级设置为Low是因为IL2CPP的高级别裁剪是按照Type.Member引用处理的(这个属性/方法你没有用到, 那么就会被裁剪). 或者在link.xml配置中插入标签preserve="all"来保留所有类型或所有成员

Another-Ghost commented 5 days ago

谢谢,我之后试一下