WebGLInput icon indicating copy to clipboard operation
WebGLInput copied to clipboard

I always receive the exception: Cannot read properties of null (reading 'getElementsByTagName')

Open sandrade-dcl opened this issue 2 years ago • 2 comments

I'm using the WebGLInput script in my input field (it is a TMP_InputField), and when I test it in my WebGL build, just when I put the focus on the input textbox, the execution is frozen and I receive these error logs in the Chrome console:

Error logs

rollbar.min.js:1 exception thrown: TypeError: Cannot read properties of null (reading 'getElementsByTagName'),TypeError: Cannot read properties of null (reading 'getElementsByTagName')
    at _WebGLInputCreate (https://renderer-artifacts.decentraland.org/branch/fix/cjk-fonts-issues/unity.framework.js.br?v=1653067972662:408:56004)
    at _WebGLInputPlugin_WebGLInputCreate_m285C4119EA43278205F4BBED9564AE827288F456 (https://renderer-artifacts.decentraland.org/branch/fix/cjk-fonts-issues/unity.wasm.br?v=1653067972662:wasm-function[127768]:0x200473a)
    at _WebGLInput_OnSelect_mA26F770E527D1E37BA62A28B7202E2491C9D5CDF (https://renderer-artifacts.decentraland.org/branch/fix/cjk-fonts-issues/unity.wasm.br?v=1653067972662:wasm-function[127767]:0x20044de)
    at _WebGLInput_Update_mB2E249ED9D67301C1B3993B0C6087CA81D2D4066 (https://renderer-artifacts.decentraland.org/branch/fix/cjk-fonts-issues/unity.wasm.br?v=1653067972662:wasm-function[127781]:0x2004b8b)
    at __Z65RuntimeInvoker_TrueVoid_t700C6383A2A510C2CF4DD86DABD5CA9FF70ADAC5PFvvEPK10MethodInfoPvPS4_ (https://renderer-artifacts.decentraland.org/branch/fix/cjk-fonts-issues/unity.wasm.br?v=1653067972662:wasm-function[126254]:0x1fdae04)
    at dynCall_iiiii (https://renderer-artifacts.decentraland.org/branch/fix/cjk-fonts-issues/unity.wasm.br?v=1653067972662:wasm-function[128463]:0x2020ef0)
    at Object.dynCall_iiiii (https://renderer-artifacts.decentraland.org/branch/fix/cjk-fonts-issues/unity.framework.js.br?v=1653067972662:408:534043)
    at invoke_iiiii (https://renderer-artifacts.decentraland.org/branch/fix/cjk-fonts-issues/unity.framework.js.br?v=1653067972662:408:365569)
    at __ZN6il2cpp2vm7Runtime6InvokeEPK10MethodInfoPvPS5_PP15Il2CppException (https://renderer-artifacts.decentraland.org/branch/fix/cjk-fonts-issues/unity.wasm.br?v=1653067972662:wasm-function[122183]:0x1f64817)
    at _il2cpp_runtime_invoke (https://renderer-artifacts.decentraland.org/branch/fix/cjk-fonts-issues/unity.wasm.br?v=1653067972662:wasm-function[120889]:0x1f3da08)
    at __Z23scripting_method_invoke18ScriptingMethodPtr18ScriptingObjectPtrR18ScriptingArgumentsP21ScriptingExceptionPtrb (https://renderer-artifacts.decentraland.org/branch/fix/cjk-fonts-issues/unity.wasm.br?v=1653067972662:wasm-function[5531]:0x25722d)
    at __ZN19ScriptingInvocation6InvokeEP21ScriptingExceptionPtrb (https://renderer-artifacts.decentraland.org/branch/fix/cjk-fonts-issues/unity.wasm.br?v=1653067972662:wasm-function[5529]:0x256f19)
    at __ZN13MonoBehaviour16CallUpdateMethodEi (https://renderer-artifacts.decentraland.org/branch/fix/cjk-fonts-issues/unity.wasm.br?v=1653067972662:wasm-function[12156]:0x48c0e0)
    at __ZN13MonoBehaviour6UpdateEv (https://renderer-artifacts.decentraland.org/branch/fix/cjk-fonts-issues/unity.wasm.br?v=1653067972662:wasm-function[12128]:0x48ab8d)
    at __ZN20BaseBehaviourManager12CommonUpdateI16BehaviourManagerEEvv (https://renderer-artifacts.decentraland.org/branch/fix/cjk-fonts-issues/unity.wasm.br?v=1653067972662:wasm-function[14625]:0x5bbcc3)
    at __ZN13UpdateManager6UpdateEv (https://renderer-artifacts.decentraland.org/branch/fix/cjk-fonts-issues/unity.wasm.br?v=1653067972662:wasm-function[14624]:0x5bb9dc)
    at __ZZ23InitPlayerLoopCallbacksvEN41UpdateScriptRunBehaviourUpdateRegistrator7ForwardEv (https://renderer-artifacts.decentraland.org/branch/fix/cjk-fonts-issues/unity.wasm.br?v=1653067972662:wasm-function[12656]:0x4bb30a)
    at __Z17ExecutePlayerLoopP22NativePlayerLoopSystem (https://renderer-artifacts.decentraland.org/branch/fix/cjk-fonts-issues/unity.wasm.br?v=1653067972662:wasm-function[12272]:0x495b36)
    at __Z17ExecutePlayerLoopP22NativePlayerLoopSystem (https://renderer-artifacts.decentraland.org/branch/fix/cjk-fonts-issues/unity.wasm.br?v=1653067972662:wasm-function[12272]:0x495b4b)
    at __Z10PlayerLoopv (https://renderer-artifacts.decentraland.org/branch/fix/cjk-fonts-issues/unity.wasm.br?v=1653067972662:wasm-function[12260]:0x495688)
    at __ZL8MainLoopv (https://renderer-artifacts.decentraland.org/branch/fix/cjk-fonts-issues/unity.wasm.br?v=1653067972662:wasm-function[12248]:0x49396b)
    at dynCall_v (https://renderer-artifacts.decentraland.org/branch/fix/cjk-fonts-issues/unity.wasm.br?v=1653067972662:wasm-function[128569]:0x2021b7f)
    at Object.dynCall_v (https://renderer-artifacts.decentraland.org/branch/fix/cjk-fonts-issues/unity.framework.js.br?v=1653067972662:408:547221)
    at browserIterationFunc (https://renderer-artifacts.decentraland.org/branch/fix/cjk-fonts-issues/unity.framework.js.br?v=1653067972662:408:189514)
    at Object.runIter (https://renderer-artifacts.decentraland.org/branch/fix/cjk-fonts-issues/unity.framework.js.br?v=1653067972662:408:192575)
    at Array.Browser_mainLoop_runner (https://renderer-artifacts.decentraland.org/branch/fix/cjk-fonts-issues/unity.framework.js.br?v=1653067972662:408:191037)
    at tick (https://renderer-artifacts.decentraland.org/branch/fix/cjk-fonts-issues/unity.framework.js.br?v=1653067972662:363:28)
Uncaught TypeError: Cannot read properties of null (reading 'getElementsByTagName')
    at _WebGLInputCreate (unity.framework.js.br?v=1653067972662:408:56004)
    at _WebGLInputPlugin_WebGLInputCreate_m285C4119EA43278205F4BBED9564AE827288F456 (unity.wasm.br?v=1653067972662:0x200473a)
    at _WebGLInput_OnSelect_mA26F770E527D1E37BA62A28B7202E2491C9D5CDF (unity.wasm.br?v=1653067972662:0x20044de)
    at _WebGLInput_Update_mB2E249ED9D67301C1B3993B0C6087CA81D2D4066 (unity.wasm.br?v=1653067972662:0x2004b8b)
    at __Z65RuntimeInvoker_TrueVoid_t700C6383A2A510C2CF4DD86DABD5CA9FF70ADAC5PFvvEPK10MethodInfoPvPS4_ (unity.wasm.br?v=1653067972662:0x1fdae04)
    at dynCall_iiiii (unity.wasm.br?v=1653067972662:0x2020ef0)
    at Object.dynCall_iiiii (unity.framework.js.br?v=1653067972662:408:534043)
    at invoke_iiiii (unity.framework.js.br?v=1653067972662:408:365569)
    at __ZN6il2cpp2vm7Runtime6InvokeEPK10MethodInfoPvPS5_PP15Il2CppException (unity.wasm.br?v=1653067972662:0x1f64817)
    at _il2cpp_runtime_invoke (unity.wasm.br?v=1653067972662:0x1f3da08)
    at __Z23scripting_method_invoke18ScriptingMethodPtr18ScriptingObjectPtrR18ScriptingArgumentsP21ScriptingExceptionPtrb (unity.wasm.br?v=1653067972662:0x25722d)
    at __ZN19ScriptingInvocation6InvokeEP21ScriptingExceptionPtrb (unity.wasm.br?v=1653067972662:0x256f19)
    at __ZN13MonoBehaviour16CallUpdateMethodEi (unity.wasm.br?v=1653067972662:0x48c0e0)
    at __ZN13MonoBehaviour6UpdateEv (unity.wasm.br?v=1653067972662:0x48ab8d)
    at __ZN20BaseBehaviourManager12CommonUpdateI16BehaviourManagerEEvv (unity.wasm.br?v=1653067972662:0x5bbcc3)
    at __ZN13UpdateManager6UpdateEv (unity.wasm.br?v=1653067972662:0x5bb9dc)
    at __ZZ23InitPlayerLoopCallbacksvEN41UpdateScriptRunBehaviourUpdateRegistrator7ForwardEv (unity.wasm.br?v=1653067972662:0x4bb30a)
    at __Z17ExecutePlayerLoopP22NativePlayerLoopSystem (unity.wasm.br?v=1653067972662:0x495b36)
    at __Z17ExecutePlayerLoopP22NativePlayerLoopSystem (unity.wasm.br?v=1653067972662:0x495b4b)
    at __Z10PlayerLoopv (unity.wasm.br?v=1653067972662:0x495688)
    at __ZL8MainLoopv (unity.wasm.br?v=1653067972662:0x49396b)
    at dynCall_v (unity.wasm.br?v=1653067972662:0x2021b7f)
    at Object.dynCall_v (unity.framework.js.br?v=1653067972662:408:547221)
    at browserIterationFunc (unity.framework.js.br?v=1653067972662:408:189514)
    at Object.runIter (unity.framework.js.br?v=1653067972662:408:192575)
    at Array.Browser_mainLoop_runner (unity.framework.js.br?v=1653067972662:408:191037)
    at tick (unity.framework.js.br?v=1653067972662:363:28)

Chrome console screenshot

image

My input field configuration in Unity

image image

Unity version used

Unity 2020.3.0f1

Thanks in advance! :)

sandrade-dcl avatar May 20 '22 17:05 sandrade-dcl

@sandrade-dcl If you have recently updated your Unity from 2019 it may be the same problem. In my case, I solved the issue by changing the following part of the html template.

Before the change <div id="unityContainer"> After the change <div id="unity-container">

Hope this helps.

jmpy avatar Jun 02 '22 05:06 jmpy

@sandrade-dcl If you have recently updated your Unity from 2019 it may be the same problem. In my case, I solved the issue by changing the following part of the html template.

Before the change <div id="unityContainer"> After the change <div id="unity-container">

Hope this helps.

Hey @jmpy, thanks for the workaround! I will try it! :)

sandrade-dcl avatar Jun 07 '22 21:06 sandrade-dcl

error here:
image

first there is a call to the method of container, and then a check for null

container.getElementsByTagName('canvas')[0] replace with document.getElementsByTagName('canvas')[0]

helmetica avatar Aug 19 '22 17:08 helmetica

error here: image

first there is a call to the method of container, and then a check for null

container.getElementsByTagName('canvas')[0] replace with document.getElementsByTagName('canvas')[0]

Where can change it? I'm happen this same issue

ronniechoyy avatar Aug 23 '22 09:08 ronniechoyy

@sandrade-dcl If you have recently updated your Unity from 2019 it may be the same problem. In my case, I solved the issue by changing the following part of the html template.

Before the change <div id="unityContainer"> After the change <div id="unity-container">

Hope this helps.

Where can you find <div id="unityContainer">? I don't have this in my index.html..

fanling3 avatar Sep 02 '22 15:09 fanling3

Finally I change the WebGLInput script, not on the webgl template You can find something like that on the script but th elif and else is set by commend, just delete the commend symbol Also see your webgl template canvasid is that same as the script image to this image Hope this help

ronniechoyy avatar Sep 03 '22 07:09 ronniechoyy

@sandrade-dcl If you have recently updated your Unity from 2019 it may be the same problem. In my case, I solved the issue by changing the following part of the html template.

Before the change <div id="unityContainer"> After the change <div id="unity-container">

Hope this helps.

It worked!! Thanks @jmpy 😄

sandrade-dcl avatar Sep 09 '22 15:09 sandrade-dcl

Finally I change the WebGLInput script, not on the webgl template You can find something like that on the script but th elif and else is set by commend, just delete the commend symbol Also see your webgl template canvasid is that same as the script to this. Hope this help

Yeah, after what @jmpy told me about the name of the div name, I looked for where in the code it was being used and I finally reached to the same solution that you suggest :) In my case I always use the name gameContainer for this div.

sandrade-dcl avatar Sep 09 '22 15:09 sandrade-dcl

It is definitively happening because of the name of the main div container... In my case, as I'm always using the name gameContainer for this div, I had to modify the WebGLInput code in order to set ALWAYS this name into WebGLInput.CanvasId and not others depending on the Unity version.

In my case I replaced this:

static WebGLInput()
 {
#if UNITY_2020_1_OR_NEWER
    WebGLInput.CanvasId = "unity-container";
#elif UNITY_2019_1_OR_NEWER
    WebGLInput.CanvasId = "unityContainer";
#else
    WebGLInput.CanvasId = "gameContainer";
#endif
    WebGLInputPlugin.WebGLInputInit();
}

by this:

static WebGLInput()
{
    WebGLInput.CanvasId = "gameContainer";
    WebGLInputPlugin.WebGLInputInit();
}

And it worked!

sandrade-dcl avatar Sep 09 '22 15:09 sandrade-dcl

error here: image

first there is a call to the method of container, and then a check for null

container.getElementsByTagName('canvas')[0] replace with document.getElementsByTagName('canvas')[0]

That solved my problem thx. I am using 2021.3.15f1. For the one who couldn't find the file, it is "webgl-build.framework.js". Which is one of the four files in your Build folder.

KubilayHeterometa avatar Apr 14 '23 13:04 KubilayHeterometa

error here: image first there is a call to the method of container, and then a check for null container.getElementsByTagName('canvas')[0] replace with document.getElementsByTagName('canvas')[0]

That solved my problem thx. I am using 2021.3.15f1. For the one who couldn't find the file, it is "webgl-build.framework.js". Which is one of the four files in your Build folder.

This should be referenced in how to install the WebGLInput because my god, I just spent 1 hour looking for this

TreeBobber1 avatar Oct 28 '23 13:10 TreeBobber1