# The web xr motion controller teleportation can throw in its \_onXRFrame

**URL:** <https://forum.babylonjs.com/t/the-web-xr-motion-controller-teleportation-can-throw-in-its-onxrframe/12292>\
**Category:** Bugs\
**Created:** [July 7, 2020, 11:18am UTC](https://forum.babylonjs.com/t/the-web-xr-motion-controller-teleportation-can-throw-in-its-onxrframe/12292 "2020-07-07T11:18:39Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![v0q](https://avatars.discourse-cdn.com/v4/letter/v/bc79bd/32.png) [@v0q](https://forum.babylonjs.com/u/v0q)\
**Post date:** [July 7, 2020, 11:18am UTC](https://forum.babylonjs.com/t/the-web-xr-motion-controller-teleportation-can-throw-in-its-onxrframe/12292/1 "2020-07-07T11:18:39Z")

</div>

Hi, I came across a little bug where WebXRMotionControllerTeleportation will throw with the following error “Uncaught TypeError: Cannot read property ‘teleportationState’ of undefined” in its \_onXRFrame.

This happens when a teleportation timer is started and the user leaves the XR session, after this upon re-entering the XR session the \_onXRFrame throws. Apparently this is due to _\_currentTeleportationControllerId_ being set by the timer but it will not be cleared upon exiting the session, now after re-entering the session, the _\_currentTeleportationControllerId_ is still set but no controllers exist yet. The line that throws is [Babylon.js/WebXRControllerTeleportation.ts at master · BabylonJS/Babylon.js · GitHub](https://github.com/BabylonJS/Babylon.js/blob/master/src/XR/features/WebXRControllerTeleportation.ts#L340)

This was reproducible in the playground using GearVR as well as the WebXR emulator. Basically if you leave the XR session when the following is happening

 ![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/2X/0/057867e2245b61f2752b81acae1f91ee59ad8788.jpeg)  
and try to re-enter the session, it will throw.

I managed to get it fixed in my application by setting _\_currentTeleportationControllerId_ to an empty string (same thing that is done after teleportation is finished) when an XR session ends. So I guess you could add an observer to xrSessionManager’s onXRSessionEnded which would clear the state properly?

---

<div class="post-metadata">

**Author:** ![RaananW](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/raananw/32/28955_2.png) [@RaananW](https://forum.babylonjs.com/u/RaananW)\
**Post date:** [July 7, 2020, 12:08pm UTC](https://forum.babylonjs.com/t/the-web-xr-motion-controller-teleportation-can-throw-in-its-onxrframe/12292/2 "2020-07-07T12:08:37Z")

</div>

Sure! Will solve that asap.

Thanks for reporting!

---

<div class="post-metadata">

**Author:** ![RaananW](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/raananw/32/28955_2.png) [@RaananW](https://forum.babylonjs.com/u/RaananW)\
**Post date:** [July 7, 2020, 12:38pm UTC](https://forum.babylonjs.com/t/the-web-xr-motion-controller-teleportation-can-throw-in-its-onxrframe/12292/3 "2020-07-07T12:38:11Z")

</div>

Done - [[XR] Teleportation fix and optional required features by RaananW · Pull Request #8499 · BabylonJS/Babylon.js · GitHub](https://github.com/BabylonJS/Babylon.js/pull/8499) , will be merged soon

---

<div class="post-metadata">

**Author:** ![v0q](https://avatars.discourse-cdn.com/v4/letter/v/bc79bd/32.png) [@v0q](https://forum.babylonjs.com/u/v0q)\
**Post date:** [July 7, 2020, 12:39pm UTC](https://forum.babylonjs.com/t/the-web-xr-motion-controller-teleportation-can-throw-in-its-onxrframe/12292/4 "2020-07-07T12:39:45Z")

</div>

Thanks for the quick response and fix
