# Camera gets detached after touch event + dispose() on mobile

**URL:** <https://forum.babylonjs.com/t/camera-gets-detached-after-touch-event-dispose-on-mobile/9138>\
**Category:** Bugs\
**Created:** [March 11, 2020, 5:55pm UTC](https://forum.babylonjs.com/t/camera-gets-detached-after-touch-event-dispose-on-mobile/9138 "2020-03-11T17:55:07Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![bigrig](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/bigrig/32/5548_2.png) [@bigrig](https://forum.babylonjs.com/u/bigrig)\
**Post date:** [March 11, 2020, 5:55pm UTC](https://forum.babylonjs.com/t/camera-gets-detached-after-touch-event-dispose-on-mobile/9138/1 "2020-03-11T17:55:07Z")

</div>

Took me a while to track this one down. Here’s the sequence:

1. Import GLB and add to scene
2. Add Gizmo to mesh on pick
3. On pointer double tap, dispose() of the mesh or bounding box

Voila, the camera is detached from canvas. Reattach and you’re good to go again. Behavior does not occur on desktop. And doesn’t occur on mobile if dispose() is run from the console. Only after a touch event.

Not a big deal, since I can just re-attach… but wanted to log it.

---

<div class="post-metadata">

**Author:** ![sebavan](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/sebavan/32/57_2.png) [@sebavan](https://forum.babylonjs.com/u/sebavan)\
**Post date:** [March 11, 2020, 8:03pm UTC](https://forum.babylonjs.com/t/camera-gets-detached-after-touch-event-dispose-on-mobile/9138/2 "2020-03-11T20:03:55Z")

</div>

I am not able to repro in the playground, do you have a repro we could use ? so that we can fix it ASAP ?

---

<div class="post-metadata">

**Author:** ![bigrig](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/bigrig/32/5548_2.png) [@bigrig](https://forum.babylonjs.com/u/bigrig)\
**Post date:** [March 11, 2020, 8:26pm UTC](https://forum.babylonjs.com/t/camera-gets-detached-after-touch-event-dispose-on-mobile/9138/3 "2020-03-11T20:26:37Z")

</div>

Oh, looks like it’s repro-ing on desktop now too.

Here: [https://dfilm.com/](https://dfilm.com/)

1. Add an object using the UI (load mesh)
2. Double click (or double tap) to delete it
3. Camera is now detached

Delete runs boundingbox.dispose() - which is on line 184 of object\_manager.js.

- If I comment out that line, camera doesn’t detach.
- If I run that line from console, camera doesn’t detach. To run from console line, do: g.objectManager.myObjs[0].handler\_boundingbox.dispose();
- If I reattach the camera with g.camManager.attachControl(), it works again.

Here’s how you add object (click add):

 ![Screen Shot 2020-03-11 at 1.24.47 PM](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/2X/a/ad238ad41d646f8c5b94247b948cbc9bbbb5259c.jpeg)

---

<div class="post-metadata">

**Author:** ![sebavan](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/sebavan/32/57_2.png) [@sebavan](https://forum.babylonjs.com/u/sebavan)\
**Post date:** [March 11, 2020, 8:32pm UTC](https://forum.babylonjs.com/t/camera-gets-detached-after-touch-event-dispose-on-mobile/9138/4 "2020-03-11T20:32:44Z")

</div>

Unfortunately it is hard to debug in your app for us ☹ would it be possible to repro in the playground instead ? This would be more efficient for us to be able to fix.

---

<div class="post-metadata">

**Author:** ![bigrig](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/bigrig/32/5548_2.png) [@bigrig](https://forum.babylonjs.com/u/bigrig)\
**Post date:** [March 11, 2020, 8:40pm UTC](https://forum.babylonjs.com/t/camera-gets-detached-after-touch-event-dispose-on-mobile/9138/5 "2020-03-11T20:40:29Z")

</div>

Was hoping you wouldn’t say that…  
I’ll work on it…

---

<div class="post-metadata">

**Author:** ![bigrig](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/bigrig/32/5548_2.png) [@bigrig](https://forum.babylonjs.com/u/bigrig)\
**Post date:** [March 11, 2020, 10:25pm UTC](https://forum.babylonjs.com/t/camera-gets-detached-after-touch-event-dispose-on-mobile/9138/6 "2020-03-11T22:25:35Z")

</div>

OK, i repro’d it:  
[https://www.babylonjs-playground.com/#ZJYNY#275](https://www.babylonjs-playground.com/#ZJYNY#275)

Double click the sphere to detach camera.  
(sorry ugly code. working quick)

ps. Note that if you double click anywhere other than the sphere, camera does not detach. Which makes me think that it has something to do with running the pick event and attach gizmo process at the same time that the double-click event is doing a dispose().

---

<div class="post-metadata">

**Author:** ![sebavan](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/sebavan/32/57_2.png) [@sebavan](https://forum.babylonjs.com/u/sebavan)\
**Post date:** [March 11, 2020, 11:32pm UTC](https://forum.babylonjs.com/t/camera-gets-detached-after-touch-event-dispose-on-mobile/9138/7 "2020-03-11T23:32:59Z")

</div>

Ohhhhhhh so the camera is not detached but it feels like it because you dispose the mesh without disposing the gizmo.

[https://www.babylonjs-playground.com/#ZJYNY#276](https://www.babylonjs-playground.com/#ZJYNY#276)

Demo pg works only if you click the mesh once and then double tap somewhere else.

---

<div class="post-metadata">

**Author:** ![bigrig](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/bigrig/32/5548_2.png) [@bigrig](https://forum.babylonjs.com/u/bigrig)\
**Post date:** [March 11, 2020, 11:37pm UTC](https://forum.babylonjs.com/t/camera-gets-detached-after-touch-event-dispose-on-mobile/9138/8 "2020-03-11T23:37:12Z")

</div>

You sure?  
After deleting the sphere by double clicking on it, if you run  
`scene.cameras[0].attachControl(canvas, false)`  
In console, you get camera control back again…  
(in my production code, i set the gizmo’s attachedMesh to null… just skipped that here)

---

<div class="post-metadata">

**Author:** ![sebavan](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/sebavan/32/57_2.png) [@sebavan](https://forum.babylonjs.com/u/sebavan)\
**Post date:** [March 12, 2020, 1:04am UTC](https://forum.babylonjs.com/t/camera-gets-detached-after-touch-event-dispose-on-mobile/9138/9 "2020-03-12T01:04:39Z")

</div>

As you kill the mesh during the pointer events, the dragbehavior which plays with the event to detach attach the camera to allow dragging, can not catch the final up event to reattach the camera.

It is why you need to kill it separately to force the reattach.

I ll see if I can include it automatically.
