unity webgl 與 ios 15.4

問題環(huán)境

unity 2022.3.14f1
ios 15.4
使用puerts作為熱更框架

發(fā)現(xiàn)在一位同事的iphone手機進不去游戲,看日志有如下報錯,看日志是內(nèi)存問題:


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,發(fā)現(xiàn)這個帖子:
https://discussions.unity.com/t/ios-15-webgl-2-issue/857077/28

帖子討論中提到下述幾點:

  1. ios 15.4的bug,已經(jīng)匯報給apple,apple也在處理了,而且截至目前為止,更新ios系統(tǒng)也可以解決此問題
  2. 部分人表示使用webgl 1可解決此問題
  3. 討論中提到wasm代碼>9m會引發(fā)此問題,<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.

也就是把下圖函數(shù)的clang優(yōu)化關閉:


img_v3_02n7_32e54b85-dbca-46b1-a1d7-f3547bf6e74g.jpg

同時刪除Library/Bee/artifacts/WebGL/il2cpp,然后重新構建一次,Not implemented: Class::FromIl2CppType的報錯消失了,但是內(nèi)存問題依然沒解決,雖然同事有一定概率可以進入游戲了,但是很快又遇到內(nèi)存問題。

再嘗試一下將auto graphic改成webgl 1,重新打包,運行小游戲,得到另一堆錯誤提示:
Desired shader compiler platform 9 is not available in shader blob

image.png

只能作罷,放棄webgl 1。問題沒徹底解決,只能升級ios系統(tǒng)了。

?著作權歸作者所有,轉載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容