问题环境
unity 2022.3.14f1
ios 15.4
使用puerts作为热更框架
发现在一位同事的iphone手机进不去游戏,看日志有如下报错,看日志是内存问题:

img_v3_02n6_6c89f561-67a2-4034-bab9-8ba27e32c02g.jpg
日志中有:Not implemented: Class::FromIl2CppType。从这句可看出和unity il2cpp有关,来自unity编辑器下关于il2cpp的源码

img_v3_02n6_02b81901-d5f9-4db2-a888-709c50079deg.jpg
puerts调用了此方法:

img_v3_02n6_57567f35-1301-492f-8497-5e53e952269g.jpg
通过一番google,发现这个帖子:
https://discussions.unity.com/t/ios-15-webgl-2-issue/857077/28
帖子讨论中提到下述几点:
- ios 15.4的bug,已经汇报给apple,apple也在处理了,而且截至目前为止,更新ios系统也可以解决此问题
- 部分人表示使用webgl 1可解决此问题
- 讨论中提到wasm代码>9m会引发此问题,<9m则不会
其中明确指出了ios 15.4的bug:

img_v3_02n6_eae1cea1-1d45-48e8-b5b2-851a573f1e3g.jpg
unity工作人员提供了一个work around:
Since it can’t get any worse than it already is:
In your Unity installation (on MacOS, in Unity.app/Contents), edit:
il2cpp/libil2cpp/metadata/GenericMetadata.cpp
Find the line:
const Il2CppType* GenericMetadata::InflateIfNeeded
Add:
#pragma clang optimize off
to the line before that function to turn off compiler optimizations for the function, and add
#pragma clang optimize on
after the end of that function to turn compiler optimizations back on again. This will disable compiler optimizations for that one function. In my tests, this has been enough to stop the crash.
In your Unity project, delete the directory Library/Bee/artifacts/WebGL/il2cpp to be sure it picks up the changes to that file. Also make sure your iOS Safari isn’t trying to load a cached version by going to Settings / Safari and selecting Clear History and Website Data. I’ve spent plenty of time chasing ghosts by not clearing a cache.
Memory errors are notoriously hard to track down, especially when only one platform, and one version of that platform, has the memory corruption, and that platform is iOS.
也就是把下图函数的clang优化关闭:

img_v3_02n7_32e54b85-dbca-46b1-a1d7-f3547bf6e74g.jpg
同时删除Library/Bee/artifacts/WebGL/il2cpp,然后重新构建一次,Not implemented: Class::FromIl2CppType的报错消失了,但是内存问题依然没解决,虽然同事有一定概率可以进入游戏了,但是很快又遇到内存问题。
再尝试一下将auto graphic改成webgl 1,重新打包,运行小游戏,得到另一堆错误提示:
Desired shader compiler platform 9 is not available in shader blob

image.png
只能作罢,放弃webgl 1。问题没彻底解决,只能升级ios系统了。