unity+puerts转微信小游戏踩坑记录

TypeError: video.canPlayType is not a function

image.png

原因是游戏里使用了VideoPlayer,然而小游戏虽然支持视频播放能力,但暂无法直接使用VideoPlayer。
参见:小游戏是否支持Unity VideoPlayer
解决方案:https://github.com/wechat-miniprogram/minigame-unity-webgl-transform/tree/main/Demo/WX_Video

某些AB包加载失败

原因竟然是美术制作的部分图片后缀名部分包含了两个..,比如abc..png,正常的Android/PC等都没问题,但小游戏会报404,重命名即可。

企业微信截图_16801639077548.png

ios真机报错:Invalid regular expression: invalid group specifier name

开发者工具模拟器可以正常运行,Android机也可以,但ios机器报错,意思是非法的正则表达式,见
https://developers.weixin.qq.com/community/develop/doc/000e6cb25b49284c9a094417256c00?highLine=Invalid%2520regular%2520expression
其实就是诸如(?<=)(?<!)(?=)(?!)这些正则表达式ios不支持~

unity input无法输入

需要做输入法适配:https://github.com/wechat-miniprogram/minigame-unity-webgl-transform/blob/main/Design/InputAdaptation.md

开启profilingFuncs和ProfilingMemory后导出webgl工程失败

stderr:INFO:root:generating system library: dlmalloc_tracing.bc... (this will be cached in "C:\Program Files\Unity2019.4.18f1\Editor\Data\PlaybackEngines\WebGLSupport\BuildTools\Emscripten_FastComp_Win\cache\asmjs\dlmalloc_tracing.bc" for subsequent builds)
Traceback (most recent call last):  File "C:\Program Files\Unity2019.4.18f1\Editor\Data\PlaybackEngines\WebGLSupport\BuildTools\Emscripten\emcc.py", line 3063, in <module>    sys.exit(run())  File "C:\Program Files\Unity2019.4.18f1\Editor\Data\PlaybackEngines\WebGLSupport\BuildTools\Emscripten\emcc.py", line 1632, in run    extra_files_to_link += system_libs.calculate([f for _, f in sorted(temp_files)] + extra_files_to_link, in_temp, stdout_=None, stderr_=None, forced=forced_stdlibs)  File "C:\Program Files\Unity2019.4.18f1\Editor\Data\PlaybackEngines\WebGLSupport\BuildTools\Emscripten\tools\system_libs.py", line 618, in calculate    libfile = shared.Cache.get(name, do_create, extension=suffix)  File "C:\Program Files\Unity2019.4.18f1\Editor\Data\PlaybackEngines\WebGLSupport\BuildTools\Emscripten\tools\cache.py", line 103, in get    shutil.copyfile(temp, cachename)  File "C:\Program Files\Unity2019.4.18f1\Editor\Data\PlaybackEngines\WebGLSupport\BuildTools\Emscripten_Win\python\2.7.5.3_64bit\lib\shutil.py", line 83, in copyfile    with open(dst, 'wb') as fdst:IOError: [Errno 13] Permission denied: 'C:\\Program Files\\Unity2019.4.18f1\\Editor\\Data\\PlaybackEngines\\WebGLSupport\\BuildTools\\Emscripten_FastComp_Win\\cache\\asmjs\\dlmalloc_tracing.bc'[WEBGL]Exception: Failed building WebGL Player.

我使用的是2019.4.18f1,估计是版本问题,考虑更换版本:
https://github.com/wechat-miniprogram/minigame-unity-webgl-transform/blob/main/Design/UnityVersion.md

InvalidOperationException: The build target does not support build appending.

原先使用2019.4.18f1时,导出webgl工程是没问题的,改用2021.3.16f1后,导出webgl工程会报错:

InvalidOperationException: The build target does not support build appending.
  at UnityEditor.BuildPipeline.BuildPlayer (System.String[] scenes, System.String locationPathName, System.String assetBundleManifestPath, UnityEditor.BuildTargetGroup buildTargetGroup, UnityEditor.BuildTarget target, System.Int32 subtarget, UnityEditor.BuildOptions options, System.String[] extraScriptingDefines) [0x00068] in <11d97693183d4a6bb35c29ae7882c66b>:0 
  at UnityEditor.BuildPipeline.BuildPlayer (UnityEditor.BuildPlayerOptions buildPlayerOptions) [0x00039] in <11d97693183d4a6bb35c29ae7882c66b>:0 
  at UnityEditor.BuildPipeline.BuildPlayer (System.String[] levels, System.String locationPathName, UnityEditor.BuildTarget target, UnityEditor.BuildOptions options) [0x0004b] in <11d97693183d4a6bb35c29ae7882c66b>:0 
  at BuildCommand.BuildForWebGL () [0x00022] in F:\games\MuWebGL_Develop\project\Assets\Editor\Builder\BuildCommand.cs:182 

报错大意是:指定的编译目标(这里是BuildTarget.WebGL)不支持增量编译
查到一篇类似的贴子:https://forum.unity.com/threads/resolved-using-acceptexternalmodificationstoplayer-to-append-to-macos-xcode-project.1230933/
查到unity的文档:https://docs.unity3d.com/2019.4/Documentation/ScriptReference/BuildPipeline.BuildCanBeAppended.html
导出webgl工程时,直接去掉BuildOptions.AcceptExternalModificationsToPlayer,或者使用下述代码判断:

if (BuildPipeline.BuildCanBeAppended(target, location) == CanAppendBuild.Yes)
{                
       ops |= BuildOptions.AcceptExternalModificationsToPlayer;
}

BINARYEN_TRAP_MODE 问题

emcc2: error: Invalid command line option -s BINARYEN_TRAP_MODE=clamp: The wasm backend does not support a trap mode (it always clamps, in effect)[WEBGL]BuildFailedException: Incremental Player build failed!

之前打webgl后,运行时会出现float溢出的问题,于是添加了下述代码

// 2019.4.18f1需使用下述编译参数解决float越界问题
PlayerSettings.WebGL.emscriptenArgs = "-s \"BINARYEN_TRAP_MODE='clamp'\"";

unity升到2021后导出webgl工程会报上述报错,意思是这个命令行选项不支持,wasm实际上一直都回clamps,所以修改为

#if !UNITY_2021_3_OR_NEWER
        // 2019.4.18f1需使用下述编译参数解决float越界问题
        PlayerSettings.WebGL.emscriptenArgs = "-s \"BINARYEN_TRAP_MODE='clamp'\"";
#endif

Error: listen EADDRINUSE: address already in use :::54998

20:44:57:815 [WEBGL][websockify wrapper] Proxying from :54998 to localhost:34999

20:44:57:825 [WEBGL][websockify wrapper] [ERROR] events.js:292
20:44:57:826 [WEBGL]
[websockify wrapper] [ERROR]       throw er; // Unhandled 'error' event
[websockify wrapper] [ERROR]       ^
[websockify wrapper] [ERROR] Error: listen EADDRINUSE: address already in use :::54998
[websockify wrapper] [ERROR]     at Server.setupListenHandle [as _listen2] (net.js:1313:16)
[websockify wrapper] [ERROR]     at listenInCluster (net.js:1361:12)
[websockify wrapper] [ERROR]     at Server.listen (net.js:1447:7)
[websockify wrapper] [ERROR]     at new WebSocketServer (F:\Program Files\2021.3.16f1\Editor\Data\PlaybackEngines\WebGLSupport\BuildTools\websockify\node_modules\ws\lib\websocket-server.js:97:20)
20:44:57:826 [WEBGL]
[websockify wrapper] [ERROR]     at Object.<anonymous> (F:\Program Files\2021.3.16f1\Editor\Data\PlaybackEngines\WebGLSupport\BuildTools\websockify\websockify.js:178:12)
[websockify wrapper] [ERROR]     at Module._compile (internal/modules/cjs/loader.js:1138:30)
[websockify wrapper] [ERROR]     at Object.Module._extensions..js (internal/modules/cjs/loader.js:1158:10)
[websockify wrapper] [ERROR]     at Module.load (internal/modules/cjs/loader.js:986:32)
20:44:57:826 [WEBGL]
[websockify wrapper] [ERROR]     at Function.Module._load (internal/modules/cjs/loader.js:879:14)
[websockify wrapper] [ERROR]     at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
20:44:57:826 [WEBGL]
[websockify wrapper] [ERROR] Emitted 'error' event on WebSocketServer instance at:

20:44:57:826 [WEBGL][websockify wrapper] [ERROR]     at Server.emit (events.js:315:20)
20:44:57:826 [WEBGL]
[websockify wrapper] [ERROR]     at emitErrorNT (net.js:1340:8)
[websockify wrapper] [ERROR]     at processTicksAndRejections (internal/process/task_queues.js:84:21) {
20:44:57:826 [WEBGL]
[websockify wrapper] [ERROR]   code: 'EADDRINUSE',

20:44:57:826 [WEBGL][websockify wrapper] [ERROR]   errno: 'EADDRINUSE',
[websockify wrapper] [ERROR]   syscall: 'listen',

20:44:57:826 [WEBGL][websockify wrapper] [ERROR]   address: '::',
[websockify wrapper] [ERROR]   port: 54998
20:44:57:826 [WEBGL]
[websockify wrapper] [ERROR] }

用netstat查看哪个进程占用了端口,最好发现是unity 2019的nodejs,应该是之前用2019打过webgl,unity就会启用一个nodejs服务,现在用unity 2021打,同样会启用一个nodejs服务,于是报错。解决办法就是直接把正在运行的那个nodejs进程kill掉。

gzip设置

如果设置了压缩格式为gzip,那么http服务器需添加Content-Encoding:gzip,否则要勾选fallback。因为此前一直使用tomcat做的http服务器,结果没法简便地配置在response添加Content-Encoding:gzip,需要自定义Filter,也太麻烦了,索性再加一个nginx服务器,配置可以参考unity文档:
https://docs.unity3d.com/cn/current/Manual/webgl-server-configuration-code-samples.html

GameGlobal is not defined

ception thrown: ReferenceError: GameGlobal is not defined,ReferenceError: GameGlobal is not defined
    at _glClear (http://192.168.8.27/mu_develop/browser/Build/export_browser.framework.js.gz:3:367029)
    at http://192.168.8.27/mu_develop/browser/Build/export_browser.wasm.gz:wasm-function[11848]:0x36cf3b
    at http://192.168.8.27/mu_develop/browser/Build/export_browser.wasm.gz:wasm-function[74712]:0x18a3f42
    at http://192.168.8.27/mu_develop/browser/Build/export_browser.wasm.gz:wasm-function[74838]:0x18b616f
    at http://192.168.8.27/mu_develop/browser/Build/export_browser.wasm.gz:wasm-function[73716]:0x1866056
    at http://192.168.8.27/mu_develop/browser/Build/export_browser.wasm.gz:wasm-function[32066]:0xacf253
    at http://192.168.8.27/mu_develop/browser/Build/export_browser.wasm.gz:wasm-function[32066]:0xacf2c4
    at http://192.168.8.27/mu_develop/browser/Build/export_browser.wasm.gz:wasm-function[28659]:0xa1e352
    at http://192.168.8.27/mu_develop/browser/Build/export_browser.wasm.gz:wasm-function[40051]:0xd6e25b
    at browserIterationFunc (http://192.168.8.27/mu_develop/browser/Build/export_browser.framework.js.gz:3:340077)
    at callUserCallback (http://192.168.8.27/mu_develop/browser/Build/export_browser.framework.js.gz:3:293275)
    at Object.runIter (http://192.168.8.27/mu_develop/browser/Build/export_browser.framework.js.gz:3:294535)
    at Browser_mainLoop_runner (http://192.168.8.27/mu_develop/browser/Build/export_browser.framework.js.gz:3:292810)
p

之前打webgl后是可以在浏览器里跑的,后来安装了微信小游戏插件后,再打就会报上述的错误,这个GameGlobal是微信模拟浏览器的Windows用的,解决办法:

使用微信的模板,比如Assets\WebGLTemplates\WXTemplate2020\index.html,里面会定义GameGlobal
或者在自己的模板里定义一个GameGlobal

视频相关

https://github.com/wechat-miniprogram/minigame-unity-webgl-transform/tree/main/Demo/WX_Video
有人提到会引起卡顿的问题:
https://github.com/wechat-miniprogram/minigame-unity-webgl-transform/issues/736

Incremental build failed

emcc2: error: '"F:/Program Files/2021.3.16f1/Editor/Data/PlaybackEngines/WebGLSupport/BuildTools/Emscripten/node/node.exe" "F:\Program Files\2021.3.16f1\Editor\Data\PlaybackEngines\WebGLSupport\BuildTools\Emscripten\emscripten\src\compiler.js" C:\Users\CLIENT~1\AppData\Local\Temp\tmp4dbxf8g0.txt' failed (1)
*** Tundra build failed (41.65 seconds), 8 items updated, 635 evaluated
[WEBGL]Library\Bee\artifacts\WebGL\build\debug_WebGL_wasm\build.js: undefined symbol: _ZN6il2cpp2os6Thread16HasCurrentThreadEv (referenced by top-level compiled C/C++ code)[WEBGL]Library\Bee\artifacts\WebGL\build\debug_WebGL_wasm\build.js: Aborting compilation due to previous errors[WEBGL]Building Library\Bee\artifacts\WebGL\build\debug_WebGL_wasm\build.js failed with output:
emcc2: error: '"F:/Program Files/2021.3.16f1/Editor/Data/PlaybackEngines/WebGLSupport/BuildTools/Emscripten/node/node.exe" "F:\Program Files\2021.3.16f1\Editor\Data\PlaybackEngines\WebGLSupport\BuildTools\Emscripten\emscripten\src\compiler.js" C:\Users\CLIENT~1\AppData\Local\Temp\tmp4dbxf8g0.txt' failed (1)[WEBGL]BuildFailedException: Incremental Player build failed!

论坛上有人遇到相同的问题:
https://forum.unity.com/threads/build-fails-with-undefined-symbol-_zn6il2cpp2os6thread16hascurrentthreadev.1359299/
我使用的是Unity 2021.3.16f1,经过测试,BuildOptions.Development并不会导致构建失败,导致失败的是BuildOptions.AllowDebuggingBuildOptions.ConnectWithProfiler

PlayerSettings.WebGL.threadsSupport导致报错

System.ArgumentException: You're trying to copy to F:/games/MuWebGL_Develop/export_browser/Build/export_browser.framework.js more than once. Previously from Library/Bee/artifacts/WebGL/build/debug_WebGL_wasm/build.framework.js and now from Library/Bee/artifacts/WebGL/build/debug_WebGL_wasm/build.worker.framework.js
   at Program.Main(String[] args)[WEBGL]BuildFailedException: Incremental Player build failed!

我用的2021.3.16f1,一开PlayerSettings.WebGL.threadsSupport就报错

Webgl Task相关问题

https://forum.unity.com/threads/async-await-and-webgl-builds.472994/
方案:https://github.com/Cysharp/UniTask

dlopen

https://emscripten.org/docs/compiling/Dynamic-Linking.html

webp

可以使用这个插件,在webgl下支持webp:
https://github.com/netpyoung/unity.webp
构建的时候可能会报

Assets\unity.webp\Runtime\NativeLibwebpdemux.cs(112,17): error CS0103: The name 'Unsafe' does not exist in the current context
Assets\unity.webp\Runtime\NativeLibwebpdemux.cs(141,17): error CS0103: The name 'Unsafe' does not exist in the current context
Assets\unity.webp\Runtime\NativeLibwebpdemux.cs(112,17): error CS0103: The name 'Unsafe' does not exist in the current context
Assets\unity.webp\Runtime\NativeLibwebpdemux.cs(141,17): error CS0103: The name 'Unsafe' does not exist in the current context

大部分情况下是因为你直接通过.package安装,缺少了System.Runtime.CompilerServices.Unsafe.dll,建议通过UMP安装,修改Packages/manifest.json:

{
  "dependencies": {
    "com.netpyoung.webp": "https://github.com/netpyoung/unity.webp.git?path=unity_project/Assets/unity.webp#0.3.9",
    "org.nuget.system.runtime.compilerservices.unsafe": "6.0.0"
  },
  "scopedRegistries": [
    {
      "name": "Unity NuGet",
      "url": "https://unitynuget-registry.azurewebsites.net",
      "scopes": [
        "org.nuget"
      ]
    }
  ]
}

但是你可能会遇到这个报错

PrecompiledAssemblyException: Multiple precompiled assemblies with the same name System.Runtime.CompilerServices.Unsafe.dll included or the current platform. Only one assembly with the same name is allowed per platform. Assembly paths: 
Assets/WX-WASM-SDK/Editor/TextureEditor/Release/System.Runtime.CompilerServices.Unsafe.dll
D:/works/qj2d/webgl/project/Library/PackageCache/org.nuget.system.runtime.compilerservices.unsafe@6.0.0/System.Runtime.CompilerServices.Unsafe.dll
UnityEditor.Scripting.ScriptCompilation.EditorBuildRules.ValidateAndGetNameToPrecompiledAssembly (UnityEditor.Scripting.ScriptCompilation.PrecompiledAssembly[] precompiledAssemblies) (at <afa5b9a1793446ff98b741dc036c4c6e>:0)
UnityEditor.Scripting.ScriptCompilation.EditorBuildRules.ToScriptAssemblies (System.Collections.Generic.IDictionary`2[TKey,TValue] targetAssemblies, UnityEditor.Scripting.ScriptCompilation.ScriptAssemblySettings settings, UnityEditor.Scripting.ScriptCompilation.EditorBuildRules+CompilationAssemblies assemblies, System.Collections.Generic.HashSet`1[T] runUpdaterAssemblies) (at <afa5b9a1793446ff98b741dc036c4c6e>:0)

因为微信插件里也用到了System.Runtime.CompilerServices.Unsafe.dll。这个问题本质上是微信小游戏插件依赖不规范,直接就把第三方插件放进文件夹里,这样就很容易和其他第三方插件冲突,我遇到的情况是,WX-WASM-SDK使用的是4.0.1,而uni.webp用的是6.0.0。最终解决办法:

  1. 不要通过UMP安装unity.webp,直接用.unitypackage安装
  2. System.Runtime.CompilerServices.Unsafe.dll复制到unity.webp/Runtime

多线程

unity webgl对多线程支持很有限...不支持C#的多线程,只支持c++级别的,参考
https://docs.unity3d.com/ScriptReference/PlayerSettings.WebGL-threadsSupport.html
有个方案,没亲试:
https://medium.com/medialesson/so-you-want-to-use-multithreading-in-unity-webgl-5953769dd337

关闭提示

https://answers.unity.com/questions/1210601/webgl-build-callback-on-tab-close-or-browser-quit.html

中文字体问题

暂时不支持使用系统字体,必须打包字体~见以下讨论:
https://github.com/wechat-miniprogram/minigame-unity-webgl-transform/issues/230
https://github.com/wechat-miniprogram/minigame-unity-webgl-transform/issues/71

webgl.data太大

用AssetStudio打开看到最大的是UnitySplash-cube


image.png

使用AssetsBundleExtractor修改unity安装目录下的Editor\2021.2.18f1\Editor\Data\PlaybackEngines\WebGLSupport\BuildTools\data\unity_default_resources,讲UnitySplash-cube替换为1*1的透明图片即可。这里是修改后的下载地址

ios15.4高性能模式crash

一种方法是分包,但流程繁琐。
另一种方法是修改unity安装目录下的Editor\Data\il2cpp\libil2cpp\metadata\GenericMetadata.cpp,在函数const Il2cppType* GenericMetadata::InfilateIfNeeded上面加上#pragma clang optimize off,在函数下面加上#pragma clang optimize on。然后删除工程目录下的Library\Bee\artifacts\WebGL\il2cpp再重新导出。

首资源包报错:mismatch data size

企业微信截图_17090926067940.png

其实去年做项目A的时候也遇到过这个报错,那会是从V1升级到V2(2023-07-12),当时在github上提了个issue:
https://github.com/wechat-miniprogram/minigame-unity-webgl-transform/issues/463
现在也想不起来是咋修复的了,官方回复说升级转换工具,然而我也不知道它说的是mismatch data size的问题,还是误报首资源包没有开启gzip的问题。但我现在用的是最新的转换工具(2024-1-18),按理说不应该还出现这个问题。
看日志上有关于fileSize/defaultSize/optimilSize的信息,猜测是纹理压缩工具压缩了首资源包导致的。
于是将压缩后的首资源包(webgl-min目录下)替换为未压缩的(webgl目录下)首资源包测试一下,果然没这个报错了。

puerts webgl导致ios奔溃

如果项目中使用了https://github.com/zombieyang/puerts_unity_webgl_demo
同时使用xcode15打包,有可能导致ios初始化崩溃。
问题见
https://github.com/Tencent/puerts/issues/1619
解决方法见
https://github.com/Tencent/puerts/issues/1669

image.png

如上图,修改puerts.cpp为:

#if !defined(__EMSCRIPTEN__)

extern "C" {
    int GetArgumentValue(int infoptr, int index) {
        return infoptr | index;
    }
}

#endif

这样子解决了ios的问题,但是构webgl时引入了下述的一个新问题:

undefined symbol: GetArgumentValue (referenced by top-level compiled C/C++ code)

Building Library\Bee\artifacts\WebGL\build\debug_WebGL_wasm\build.js failed with output:
error: undefined symbol: GetArgumentValue (referenced by top-level compiled C/C++ code)
warning: Link with `-s LLD_REPORT_UNDEFINED` to get more information on undefined symbols
warning: To disable errors for undefined symbols use `-s ERROR_ON_UNDEFINED_SYMBOLS=0`
warning: _GetArgumentValue may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
Error: Aborting compilation due to previous errors
emcc2: error: '"F:/Program Files/2021.2.18f1/Editor/Data/PlaybackEngines/WebGLSupport/BuildTools/Emscripten/node/node.exe" "F:\Program Files\2021.2.18f1\Editor\Data\PlaybackEngines\WebGLSupport\BuildTools\Emscripten\emscripten\src\compiler.js" C:\Users\CLIENT~1\AppData\Local\Temp\tmp3qcxfgav.txt' failed (1)
10:29:12:047 [WEBGL]BuildFailedException: Incremental Player build failed!
  at UnityEditor.Modules.BeeBuildPostprocessor.PostProcess (UnityEditor.Modules.BuildPostProcessArgs args) [0x00165] in <1f61d5eefcc74dff84f661b4a4dc8479>:0 
  at UnityEditor.WebGL.WebGlBuildPostprocessor.PostProcess (UnityEditor.Modules.BuildPostProcessArgs args) [0x000bb] in /Users/bokken/buildslave/unity/build/PlatformDependent/WebGL/Extensions/Unity.WebGL.extensions/BuildPostprocessor.cs:158 
  at UnityEditor.Modules.DefaultBuildPostprocessor.PostProcess (UnityEditor.Modules.BuildPostProcessArgs args, UnityEditor.BuildProperties& outProperties) [0x00001] in <1f61d5eefcc74dff84f661b4a4dc8479>:0 
  at UnityEditor.PostprocessBuildPlayer.Postprocess (UnityEditor.BuildTargetGroup targetGroup, UnityEditor.BuildTarget target, System.Int32 subtarget, System.String installPath, System.String companyName, System.String productName, System.Int32 width, System.Int32 height, UnityEditor.BuildOptions options, UnityEditor.RuntimeClassRegistry usedClassRegistry, UnityEditor.Build.Reporting.BuildReport report) [0x000e5] in <1f61d5eefcc74dff84f661b4a4dc8479>:0 

很明显,构webgl时puerts.cpp中的GetArgumentValue找不到了。所以要使ios打包和webgl打包兼容,正确的做法是修改puerts.cpp的插件设置,让它仅在webgl下生效:

image.png

Uncaught ReferenceError: _memset is not defined

项目升级到unity 2022.3.14f1后,发布webgl后运行报错

Uncaught ReferenceError: _memset is not defined
    at _InitPuertsWebGL (export_browser_781486.framework.js.gz:10:39359)
    at WebGL_GetBrowserEnv_m202368040F440BE14F18095462395F27081F1F57 (export_browser_89c413.wasm.gz:0x83594f)
    at JVM_Init_mF36761B3907926989F056C942227057D26B0F877 (export_browser_89c413.wasm.gz:0x8ca414)
    at JVM_InitBrowserEnv_mD6C5EE3BB5AB462890AC2BA076E06940BEDBC001 (export_browser_89c413.wasm.gz:0x8ca2bc)
    at root_webgl_OnCheckEnd_mE2B188B0793C53430E29B7C0748E28489817DC26 (export_browser_89c413.wasm.gz:0x8d239d)
    at AssetRequest_EndLoad_mCD188F843011FBC820B0B74E492F4C17FABA0893 (export_browser_89c413.wasm.gz:0xa5ffff)
    at ResLoader_Update_m70FFEF1A8E0CDC5AC632FC54132FCBA0C0DAC786 (export_browser_89c413.wasm.gz:0x8c0c06)
    at RuntimeInvoker_TrueVoid_t4861ACF8F4594C3437BB48B6E56783494B843915(browser/void (*)(), MethodInfo const*, void*, void**, void*) (http://192.168.8.27:8484/res/doupo_webgl_develop/browser/Build/export_browser_89c413.wasm.gz)
    at il2cpp::vm::Runtime::InvokeWithThrow(browser/MethodInfo const*, void*, void**) (http://192.168.8.27:8484/res/doupo_webgl_develop/browser/Build/export_browser_89c413.wasm.gz)
    at dynCall_iiii (export_browser_89c413.wasm.gz:0x1682060)
    at invoke_iiii (export_browser_781486.framework.js.gz:10:574454)
    at il2cpp::vm::Runtime::Invoke(browser/MethodInfo const*, void*, void**, Il2CppException**) (http://192.168.8.27:8484/res/doupo_webgl_develop/browser/Build/export_browser_89c413.wasm.gz)
    at il2cpp_runtime_invoke (export_browser_89c413.wasm.gz:0xa8aab)
    at scripting_method_invoke(browser/ScriptingMethodPtr, ScriptingObjectPtr, ScriptingArguments&, ScriptingExceptionPtr*, bool) (http://192.168.8.27:8484/res/doupo_webgl_develop/browser/Build/export_browser_89c413.wasm.gz)
    at ScriptingInvocation::Invoke(browser/ScriptingExceptionPtr*, bool) (http://192.168.8.27:8484/res/doupo_webgl_develop/browser/Build/export_browser_89c413.wasm.gz)
    at MonoBehaviour::CallUpdateMethod(browser/int) (http://192.168.8.27:8484/res/doupo_webgl_develop/browser/Build/export_browser_89c413.wasm.gz)
    at MonoBehaviour::Update(browser/) (http://192.168.8.27:8484/res/doupo_webgl_develop/browser/Build/export_browser_89c413.wasm.gz)
    at BehaviourManager::Update(browser/) (http://192.168.8.27:8484/res/doupo_webgl_develop/browser/Build/export_browser_89c413.wasm.gz)
    at InitPlayerLoopCallbacks(browser/)::UpdateScriptRunBehaviourUpdateRegistrator::Forward() (http://192.168.8.27:8484/res/doupo_webgl_develop/browser/Build/export_browser_89c413.wasm.gz)
    at ExecutePlayerLoop(browser/NativePlayerLoopSystem*) (http://192.168.8.27:8484/res/doupo_webgl_develop/browser/Build/export_browser_89c413.wasm.gz)
    at ExecutePlayerLoop(browser/NativePlayerLoopSystem*) (http://192.168.8.27:8484/res/doupo_webgl_develop/browser/Build/export_browser_89c413.wasm.gz)
    at MainLoop(browser/) (http://192.168.8.27:8484/res/doupo_webgl_develop/browser/Build/export_browser_89c413.wasm.gz)
    at dynCall_v (export_browser_89c413.wasm.gz:0x168209c)
    at browserIterationFunc (export_browser_781486.framework.js.gz:10:360600)
    at callUserCallback (export_browser_781486.framework.js.gz:10:314169)
    at Object.runIter (export_browser_781486.framework.js.gz:10:315409)
    at Browser_mainLoop_runner (export_browser_781486.framework.js.gz:10:313705)

查看emscripten文档:

EXPORTED_FUNCTIONS

https://emscripten.org/docs/tools_reference/settings_reference.html?highlight=exported_functions#exported-functions
估计是unity的编译哪里变了,解决方法:

#if UNITY_2022_3_OR_NEWER
        // 2022.3.14f1报错:_memset is not defined
        PlayerSettings.WebGL.emscriptenArgs += "-s \"EXPORTED_FUNCTIONS=['_main', '_memset']\"";
#endif

同理,小游戏插件代码也要改一下:Assets/WX-WASM-SDK-V2/Editor/WXConvertCore.cs

Desired shader compiler platform 5 is not available in shader blob

此前并没有这个报错,这个问题发生在一系列修改之后的某次打包:

  1. unity从2021.2.18f1升级到2022.3.14f1
  2. 项目引入了curved world组件
  3. 升级了微信小游戏插件
    现象是真机测试时部分shader坏掉了,包括textmeshpro和curved world的相关shader。按理上述3个修改不应该会引入这个错误。网上查到的资料都说设置Auto Graphics API,直觉就都是人云亦云的瞎扯淡。何况导出微信小游戏时,在Assets/WX-WASM-SDK-V2/Editor/WXConvertCore.cs会根据是否开启webgl2设置GraphicAPI:
        public static void UpdateGraphicAPI()
        {
            GraphicsDeviceType[] targets = new GraphicsDeviceType[] { };
#if PLATFORM_WEIXINMINIGAME
            PlayerSettings.SetUseDefaultGraphicsAPIs(BuildTarget.WeixinMiniGame, false);
            if (config.CompileOptions.Webgl2)
            {
                PlayerSettings.SetGraphicsAPIs(BuildTarget.WeixinMiniGame, new GraphicsDeviceType[] { GraphicsDeviceType.OpenGLES3 });
            }
            else
            {
                PlayerSettings.SetGraphicsAPIs(BuildTarget.WeixinMiniGame, new GraphicsDeviceType[] { GraphicsDeviceType.OpenGLES2 });
            }
#else
            PlayerSettings.SetUseDefaultGraphicsAPIs(BuildTarget.WebGL, false);
            if (config.CompileOptions.Webgl2)
            {
                PlayerSettings.SetGraphicsAPIs(BuildTarget.WebGL, new GraphicsDeviceType[] { GraphicsDeviceType.OpenGLES3 });
            }
            else
            {
                PlayerSettings.SetGraphicsAPIs(BuildTarget.WebGL, new GraphicsDeviceType[] { GraphicsDeviceType.OpenGLES2 });
            }
#endif
        }

于是打算做个测试,怀疑因unity升级导致curved world插件适配有问题,于是拉了个分支,把unity回退到2021.2.18f1然后打包测试。结果阴差阳错,打包时忘记了修改配置用分支进行打包,依然用原工程进行了打包,结果一测发现报错没有了,textmeshpro也正常显示了。于是,对我而言,这个问题的解决方法就是把所有缓存清空,重新打包。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 175,490评论 5 419
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 74,060评论 2 335
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 124,407评论 0 291
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 47,741评论 0 248
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 56,543评论 3 329
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 43,040评论 1 246
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 34,107评论 3 358
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 32,646评论 0 229
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 36,694评论 1 271
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 32,398评论 2 279
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 33,987评论 1 288
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 30,097评论 3 285
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 35,298评论 3 282
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 27,278评论 0 14
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 28,413评论 1 232
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 38,397评论 2 309
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 38,099评论 2 314

推荐阅读更多精彩内容