我的网页上有一个画布,存储在负z索引处。点击一个按钮,我希望团结游戏加载使用统一脚本作为承诺。这个承诺执行得很完美,但是在脚本加载之后,我得到了一个错误
Creating WebGL 2.0 context.
unity.loader.js:1 Unable to create WebGL context.
unity.loader.js:1 exception thrown: TypeError: Cannot read properties of undefined (reading 'getParameter'),TypeError: Cannot read properties of undefined (reading 'getParameter')
at _glGetString (http://localhost:5500/scripts/unity/Build/unity.framework.js:3:248153)
at http://localhost:5500/scripts/unity/Build/unity.wasm:wasm-function[29563]:0x8cc821
at http://localhost:5500/scripts/unity/Build/unity.wasm:wasm-function[25931]:0x82d2c6
at Module._main (http://localhost:5500/scripts/unity/Build/unity.framework.js:3:299245)
at callMain (http://localhost:5500/scripts/unity/Build/unity.framework.js:3:364104)
at doRun (http://localhost:5500/scripts/unity/Build/unity.framework.js:3:364664)
at run (http://localhost:5500/scripts/unity/Build/unity.framework.js:3:364836)
at runCaller (http://localhost:5500/scripts/unity/Build/unity.framework.js:3:363763)
at Object.removeRunDependency (http://localhost:5500/scripts/unity/Build/unity.framework.js:3:16089)
at http://localhost:5500/scripts/unity/Build/unity.framework.js:3:1948
at doCallback (http://localhost:5500/scripts/unity/Build/unity.framework.js:3:92358)
at done (http://localhost:5500/scripts/unity/Build/unity.framework.js:3:92512)
at transaction.oncomplete (http://localhost:5500/scripts/unity/Build/unity.framework.js:3:85617)我有一个背景粒子效应,它使用requestAnimationFrame()运行,在统一脚本开始使用cancelAnimationFrame()加载之前结束。
我在网上找不到多少
发布于 2022-09-17 10:04:05
因此,经过30分钟的调试,问题是画布的上下文设置为2d,而统一构建是3d的。创建了一个新的画布元素,问题就解决了。
发布于 2022-09-17 10:56:12
上下文丢失在任何WebGL构建中都会发生,并且与统一无关。我找不到关于这个问题的任何细节,并且在不重新加载网页的情况下修复它。这很可能是由于浏览器中的上下文数量或它们的内存受到限制所致。
https://stackoverflow.com/questions/73749336
复制相似问题