unity微信小游戏问题记录

环境

unity 2022.3.62f1

WebGL: INVALID_ENUM: compressedTexSubImage2D: invalid format

现象
打包小游戏后,运行报错:WebGL: INVALID_ENUM: compressedTexSubImage2D: invalid format,打成图集的UI图片显示不出来,显示一片黑色。

项目状态:
· linear color space
· webgl 2
· 图片import setting里webgl默认压缩格式:RGBA 32 bit
· 采用了微信小游戏的贴图压缩功能

报错的直观意思就是压缩格式不对。下面是尝试路径:

1

修改图片压缩格式为:RGBA Compressed DXT5|BC3,经测试问题依旧。

2

在步骤1修改了图片格式的基础上,取消勾选微信小游戏上设置面板上的webgl 2.0选项(同时修改为gamma color space)。贴图黑色的问题解决了,但是textmeshpro文字都不显示了,报错:Desired shader compiler platform 5 is not available in shader blob
查了一下,这个报错的意味着出问题的资源不是用webgl 1.0构建的:

image.png

将Player Setting上的Auto Graphic API勾选去掉,移除webgl 2.0,改成webgl 1.0,重新build,textmeshpro的问题也好了。

3

虽然问题解决了,但是之前其他项目并没有此问题。为什么这次就出问题了呢?第2步将webgl 2.0改成webgl 1.0解决了问题,那第1步还有必要吗?于是将第1步的修改回滚,重新build,也是OK的,说明和图片压缩格式无关。

RuntimeError: memory access out of bounds

这个项目最早一切正常,直至项目内容越来越多,开始出现各种内存问题,比如

RuntimeError: memory access out of bounds
EntryU5BU5D_tF740C626B28CBB6757BD70F46E0AFB6A991253E3::GetAddressAt(unsigned long)
List_1_Add_mD4F3498FBD3BDD3F03CBCFB38041CBAC9C28CAFC_gshared_inline(List_1_tDBA89B0E21BAC58CFBD3C1F76E4668E3B562761A*, void*, MethodInfo const*)
List_1_Add_mD4F3498FBD3BDD3F03CBCFB38041CBAC9C28CAFC_inline(List_1_tDBA89B0E21BAC58CFBD3C1F76E4668E3B562761A*, void*, MethodInfo const*)
GraphicRaycaster_Raycast_mCBF5513CAA3AB70569DA3BE50DCF8980819A6D7F
EventSystem_RaycastAll_mE93CC75909438D20D17A0EF98348A064FBFEA528
PointerInputModule_GetMousePointerEventData_m8D8111399CF7077AEBE4836AC701DDDF3F5ADFC5
VirtualFuncInvoker1<MouseState_tCCE70861DE1EEECF949AFE8E2A922541D4E08A09*, int>::Invoke(unsigned short, Il2CppObject*, int)
StandaloneInputModule_ProcessMouseEvent_m8A8214EB9286BA31C18F515BCC3349DF740B2BBA
StandaloneInputModule_ProcessMouseEvent_mCE1BA96E47D9A4448614CB9DAF5A406754F655DD
StandaloneInputModule_Process_mBD949CC45BBCAB5A0FAF5E24F3BB4C3B22FF3E81

除了内存问题,还有诸如一下各种奇怪的报错:
比如函数签名不匹配

RuntimeError: null function or function signature mismatch
VirtualFuncInvoker0<int>::Invoke(unsigned short, Il2CppObject*)
GraphicRaycaster_Raycast_m06B8EF9AC17F7B4FBDB687E3A2C748EF575CCFCC
GraphicRaycaster_Raycast_mCBF5513CAA3AB70569DA3BE50DCF8980819A6D7F
EventSystem_RaycastAll_mE93CC75909438D20D17A0EF98348A064FBFEA528
PointerInputModule_GetMousePointerEventData_m8D8111399CF7077AEBE4836AC701DDDF3F5ADFC5
VirtualFuncInvoker1<MouseState_tCCE70861DE1EEECF949AFE8E2A922541D4E08A09*, int>::Invoke(unsigned short, Il2CppObject*, int)
StandaloneInputModule_ProcessMouseEvent_m8A8214EB9286BA31C18F515BCC3349DF740B2BBA
StandaloneInputModule_ProcessMouseEvent_mCE1BA96E47D9A4448614CB9DAF5A406754F655DD
StandaloneInputModule_Process_mBD949CC45BBCAB5A0FAF5E24F3BB4C3B22FF3E81
VirtualActionInvoker0::Invoke(unsigned short, Il2CppObject*)

比如表索引越界

RuntimeError: table index is out of bounds
Object::Produce(Unity::Type const*, Unity::Type const*, int, MemLabelId, ObjectCreationMode)
Object::Produce(Unity::Type const*, int, MemLabelId, ObjectCreationMode)
PersistentManager::CreateThreadActivationQueueEntry(SerializedFile&, SerializedObjectIdentifier, int, bool, PersistentManager::LockFlags)
PersistentManager::ReadAndActivateObjectThreaded(int, SerializedObjectIdentifier const&, SerializedFile*, bool, bool, PersistentManager::LockFlags)
PersistentManager::LoadObjectsThreaded(int const*, int, LoadProgress&, bool, PersistentManager::LockFlags, bool)
LoadOperation::Perform()
AssetBundleLoadAssetOperation::Perform()
PreloadManager::UpdatePreloadingSingleStep(PreloadManager::UpdatePreloadingFlags, int)
InitPlayerLoopCallbacks()::EarlyUpdateUpdatePreloadingRegistrator::Forward()
ExecutePlayerLoop(NativePlayerLoopSystem*)

凡此种种,一开始无法理解。为什么项目早期都没遇到这些错误,到后来偶尔遇到一两个memory out of bounds,再到后来所有设备都遇到了这个错误。这期间从代码层面应该不可能导致这一问题,结合报错大多数都和内存相关,而之前更大型的项目并没有遇到此问题。因此怀疑是unity版本的bug。将unity版本从unity 2022.3.62f1换成unity 2022.3.14f1,相关报错就没再出现。

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容