MozillaReality / unity-webxr-export

INACTIVE - Assets for creating WebXR-enabled Unity3D projects.
https://mixedreality.mozilla.org/unity-webxr-export/Build/
Apache License 2.0
622 stars 127 forks source link

Look Rotation Viewing Vector is Zero Error on third Prefab when starting VR #431

Closed belafonte closed 1 month ago

belafonte commented 3 years ago

Hello,

I got a strange issue, when loading a third Prefab into my scene and starting VR afterwards. Up to 2 of those Prefabs the VR view starts without issues, but as soon as there is a third Prefab in the Scene the console throws this Error: Look Rotation Viewing Vector is Zero - (thrown from Runtime.Math)

It is strange, because the scene works without issues with much more of those Prefabs but only breaks when staring VR Mode.

Does somebody knows how this issue can be related to the WebXR Plugin?

Testing it with a HTC Vive in Firefox on Windows 10 (Unity 2019.4.13f1).

Thanks.

De-Panther commented 3 years ago

I guess that it's related to the WebAssembly memory growth. When that happens, typed arrays on the page that refers to the WASM memory would lose the reference. Like SharedArray here https://github.com/MozillaReality/unity-webxr-export/blob/master/Assets/WebXR/Plugins/WebGL/webxr.jslib#L20 To fix it, you need to store the byteOffset, then you can check if it's byteLength == 0. Like done here: https://github.com/De-Panther/unity-webxr-export/blob/master/Packages/webxr/Runtime/Plugins/WebGL/webxr.jslib#L41

belafonte commented 3 years ago

Hey thanks for your reply. Yet I do not completely understand where I would have to implement that. If I understand you correctly, those shared arrays are built as soon as something is changed live, during runtime.

But I do not use those SharedArrays in my code.

But still I think the issue is related to that.

Since I was removing everything from my prefab, until the error disappeared. I think it might be related to the dynamic creation of RenderTextures or VideoPlayer, which render to a RenderTexture. Still strange that this only happens when starting VR Mode.

Do you have any clue why this happens, or how to solve it?

Thank you.

De-Panther commented 3 years ago

But I do not use those SharedArrays in my code.

The exporter use them, so if you use the exporter, you use them :)

As I wrote, the wasm memory grow, and then the variable named SharedArray here https://github.com/MozillaReality/unity-webxr-export/blob/39b22eb851a1c4462a3ccb5d7c9f63a137e54b0f/Assets/WebXR/Plugins/WebGL/webxr.jslib#L20 Lose it's reference.

So do the same thing that was done in this fork for Module.XRSharedArray https://github.com/De-Panther/unity-webxr-export/blob/b788ee930f0b05cdaedeaffc9f35f13563e12000/Packages/webxr/Runtime/Plugins/WebGL/webxr.jslib#L41