I have a canvas on my webpage stored at a negative z index. With a click of a button, I want the unity game to load using loading the unity script as a promise. The promise executes perfectly but after the script loads I get an error
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)
I have a background particle effect that runs using requestAnimationFrame() and ends just before the unity script starts loading using cancelAnimationFrame()
I can't find much on the internet
CodePudding user response:
So turns out, after 30 minutes of debugging the problem was that the context of the canvas was set to be 2d, while the unity build was 3d. Created a new canvas element and the problem was solved.
CodePudding user response:
Context loss happens with any WebGL build and is not related specifically to Unity. I couldn't find any details about this issue and fix it without reloading web page. Most likely this is caused by a limitation on the number of contexts in a browser or the memory for them