# ArcRotateCamera upVector crashes

**URL:** <https://forum.babylonjs.com/t/arcrotatecamera-upvector-crashes/34190>\
**Category:** Questions\
**Tags:** react\
**Created:** [September 23, 2022, 4:48pm UTC](https://forum.babylonjs.com/t/arcrotatecamera-upvector-crashes/34190 "2022-09-23T16:48:33Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Todilo](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/todilo/32/19084_2.png) [@Todilo](https://forum.babylonjs.com/u/Todilo)\
**Post date:** [September 23, 2022, 4:48pm UTC](https://forum.babylonjs.com/t/arcrotatecamera-upvector-crashes/34190/1 "2022-09-23T16:48:33Z")

</div>

I am using babylon react and if I set the arcRotateCamera upVector to anything but 0,1,0 (default) it crashes. See image below.

```auto
 <arcRotateCamera
            name="camera1"
            target={cameraRotationPoint}
            upVector={new Vector3(0, 1, 0)}
            alpha={-1}
            beta={2.5}
            radius={0}
          />

```

 ![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/0/6/0615a6e742dfe2975529d1079f768a5b589ac930.png)

I have my scene setup in a way that the arcate rotate rotates around the wrong axes and instead of rotate all object I thought maybe it is enough to change upVector.

---

<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:** [September 23, 2022, 7:11pm UTC](https://forum.babylonjs.com/t/arcrotatecamera-upvector-crashes/34190/2 "2022-09-23T19:11:19Z")

</div>

This works fine in the playground [Babylon.js Playground](https://playground.babylonjs.com/#V8SIVM)

Maybe @brianzinn would have an idea ?

---

<div class="post-metadata">

**Author:** ![brianzinn](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/brianzinn/32/28013_2.png) [@brianzinn](https://forum.babylonjs.com/u/brianzinn)\
**Post date:** [September 23, 2022, 8:32pm UTC](https://forum.babylonjs.com/t/arcrotatecamera-upvector-crashes/34190/3 "2022-09-23T20:32:30Z")

</div>

The renderer doesn’t treat that property different than other Vector3’s. ie: `target` that you are using

Do you have a repro or can share more of the code? I can try it out when I get home, but what you have ought to work.  
edit: actually easy to repro. I’ll try to track the bug tonight

---

<div class="post-metadata">

**Author:** ![brianzinn](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/brianzinn/32/28013_2.png) [@brianzinn](https://forum.babylonjs.com/u/brianzinn)\
**Post date:** [September 23, 2022, 10:20pm UTC](https://forum.babylonjs.com/t/arcrotatecamera-upvector-crashes/34190/4 "2022-09-23T22:20:07Z")

</div>

What `react-babylonjs` does is try to reduce GC memory pressure by re-using objects. Check this PG:  
[Babylon.js Playground (babylonjs.com)](https://playground.babylonjs.com/#V8SIVM#1)

This line crashes babylon:

```auto
scene.activeCamera.upVector.x = 0.6;

```

Solutionwise - I think I know the problem - it’s because we don’t call the upVector setter and other code depends directly on the vector being normalized and `setMatUp()` being called. Almost like Vector3 should publish an event, so we don’t need comments like here (but it’s well documented at least!):  
[BabylonJS/Babylon.js (github.com)](https://github.com/BabylonJS/Babylon.js/blob/master/packages/dev/core/src/Cameras/arcRotateCamera.ts#L117)

I did something similar in GUI to observe changes and update accordingly, but I think would not be considered on an essential class like Vector3:  
[add ValueAndUnit change tracking · BabylonJS/Babylon.js@9bf8875 (github.com)](https://github.com/BabylonJS/Babylon.js/commit/9bf88755c6e97171182a9284baba19b3a4f959c2)

---

<div class="post-metadata">

**Author:** ![brianzinn](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/brianzinn/32/28013_2.png) [@brianzinn](https://forum.babylonjs.com/u/brianzinn)\
**Post date:** [September 23, 2022, 11:47pm UTC](https://forum.babylonjs.com/t/arcrotatecamera-upvector-crashes/34190/5 "2022-09-23T23:47:56Z")

</div>

I can see in the TypeScript compiler when the property is a “set accessor” or not. For correctness I can deoptimize that. ie: if Babylon.js doesn’t check if the Vector3 is dirty etc. I think any solution downstream in Babylon.js will have performance impact and add some code clutter. Let’s hold off to see if this is deemed a bug - otherwise I’ll fix upstream that setters are called instead of their nested props.

@sebavan is that a bug or just by design and need to deal with it as-is? Cheers

---

<div class="post-metadata">

**Author:** ![carolhmj](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/carolhmj/32/25918_2.png) [@carolhmj](https://forum.babylonjs.com/u/carolhmj)\
**Post date:** [October 21, 2022, 3:58pm UTC](https://forum.babylonjs.com/t/arcrotatecamera-upvector-crashes/34190/6 "2022-10-21T15:58:08Z")

</div>

ping @sebavan again for visibility

---

<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:** [October 21, 2022, 8:28pm UTC](https://forum.babylonjs.com/t/arcrotatecamera-upvector-crashes/34190/7 "2022-10-21T20:28:04Z")

</div>

Thanks @carolhmj !!!

I would say it is by design mainly for perf as you mentioned.

---

<div class="post-metadata">

**Author:** ![brianzinn](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/brianzinn/32/28013_2.png) [@brianzinn](https://forum.babylonjs.com/u/brianzinn)\
**Post date:** [October 26, 2022, 4:30pm UTC](https://forum.babylonjs.com/t/arcrotatecamera-upvector-crashes/34190/8 "2022-10-26T16:30:42Z")

</div>

Thanks for official confirmation. Noted as “won’t fix”. Totally fine as it’s a really small edge case and even well documented in the property.

Once I added the fix downstream I was completely surprised how many setters there are – even the position of a TransformNode has this behaviour.  
[Babylon.js/transformNode.ts at master · BabylonJS/Babylon.js (github.com)](https://github.com/BabylonJS/Babylon.js/blob/master/packages/dev/core/src/Meshes/transformNode.ts#L198)

So setting `transformNodeInstance.position.x = 2` vs. position prop changes result of `_IsSynchronized..` resulting in essentially what looks like “non-deterministic” behaviour from seemingly identical changes. I think an audit of the library would bring to light many more potential issues. As I mentioned the fix is “easy but tedious”, but the performance and memory are of utmost importance. Definitely interesting to look at the impact of and to revisit design decisions.

---

<div class="post-metadata">

**Author:** ![brianzinn](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/brianzinn/32/28013_2.png) [@brianzinn](https://forum.babylonjs.com/u/brianzinn)\
**Post date:** [October 26, 2022, 7:02pm UTC](https://forum.babylonjs.com/t/arcrotatecamera-upvector-crashes/34190/9 "2022-10-26T19:02:04Z")

</div>

@Todilo same issue reported on github ( [ArcCamera setting upVector crash · Issue #250 · brianzinn/react-babylonjs (github.com)](https://github.com/brianzinn/react-babylonjs/issues/250)), so you can track there the fix and I think put sebavan response as solution here if you like. cheers.

---

<div class="post-metadata">

**Author:** ![brianzinn](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/brianzinn/32/28013_2.png) [@brianzinn](https://forum.babylonjs.com/u/brianzinn)\
**Post date:** [October 27, 2022, 5:34am UTC](https://forum.babylonjs.com/t/arcrotatecamera-upvector-crashes/34190/10 "2022-10-27T05:34:09Z")

</div>

hi @Todilo sorry this took so long - the code was committed to repo the day after your original question was asked! anyway - it’s out now on version 3.1.13.

---

<div class="post-metadata">

**Author:** ![Todilo](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/todilo/32/19084_2.png) [@Todilo](https://forum.babylonjs.com/u/Todilo)\
**Post date:** [October 27, 2022, 7:22am UTC](https://forum.babylonjs.com/t/arcrotatecamera-upvector-crashes/34190/11 "2022-10-27T07:22:30Z")

</div>

Thank you very much. I did a workaround in the meantime but actually need to update my code for other reasons so I will definitely check it out.
