immersive-web / webvr-polyfill

Use WebVR today, without requiring a special browser build.
http://immersive-web.github.io/webvr-polyfill/examples/
Apache License 2.0
1.4k stars 325 forks source link

Error when going into VR mode using Polyfill with Unity exporter #308

Closed tbalouet closed 6 years ago

tbalouet commented 6 years ago
Description:

Trying an experience using the Mozilla's Unity exporter on mobile, there seems to be an error when entering the VR mode. Example to test: http://adityabawankule.me/Unity/WebVR/Beach/index.html Unity-to-webvr library: https://hacks.mozilla.org/2018/02/create-vr-on-the-web-using-unity3d/ Log of the error (Range error at the end) screenshot from 2018-02-22 15-41-10

Result: it produces a distorted view of the experience, but everything's frozen and we have to leave the page.

Additional Information:
jsantell commented 6 years ago

The recursion error leaves me the believe this isn't polyfill related -- does this work on native VR platforms (S8 on Chrome should be able to enable native WebVR)? I haven't dug into the Unity WebVR exporter yet, if this works on native WebVR I'll dig into it more!

jsantell commented 6 years ago

Reading more in the exporter issues (https://github.com/mozilla/unity-webvr-export/issues/113), it appears there may be different limits in Unity's exported JS

jsantell commented 6 years ago

I was able to run this on Chrome 64 with native WebVR enabled successfully; sometimes did get an 'Uncaught RangeError: Array buffer allocation failed'.

Here's an image with more information on the recursion.

screenshot from 2018-02-23 09-52-20

It looks like webvr.js overwrites window.requestAnimationFrame with a function that calls VRDisplay's raf or a saved window.raf depending on if we're presenting or not. In polyfill land, the VRDisplay's raf ultimately calls window.requestAnimationFrame since we don't have a real VRDisplay, resulting in the recursion.

The fix here would be to cache the window.requestAnimationFrame in the polyfill, and could also be fixed by not overwriting window.raf in the Unity exporter. I suggest both! I'll make a fix for this.

jsantell commented 6 years ago

Fixed in https://github.com/immersive-web/cardboard-vr-display/commit/6f6a0c1e8b28eb4a3c861aeab4f814e93207fb85, cardboard-vr-display@1.0.6 -- need to uplift and release in the polyfill, and will need to be added in exporter via https://github.com/mozilla/unity-webvr-export/issues/113

jsantell commented 6 years ago

Fixed in 0.10.3