# Strange issue in @latest related to canvas size/settings?

**URL:** <https://forum.babylonjs.com/t/strange-issue-in-latest-related-to-canvas-size-settings/31982>\
**Category:** Questions\
**Created:** [July 7, 2022, 9:55am UTC](https://forum.babylonjs.com/t/strange-issue-in-latest-related-to-canvas-size-settings/31982 "2022-07-07T09:55:21Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![fenomas](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/fenomas/32/2309_2.png) [@fenomas](https://forum.babylonjs.com/u/fenomas)\
**Post date:** [July 7, 2022, 9:55am UTC](https://forum.babylonjs.com/t/strange-issue-in-latest-related-to-canvas-size-settings/31982/1 "2022-07-07T09:55:21Z")

</div>

I recently updated my (large nontrivial) project from Babylon `5.2.0` to `5.13.2`, and I started seeing an occasional bug. About 50% of the time, when the scene first initializes it looks like the camera is weirdly zoomed in on the lower-left part of the scene. The issue seems to be related to `canvas` properties, because if I change the width or height of the canvas that Babylon is rendering into, the scene starts rendering correctly.

In trying to isolate the bug, I noticed by accident that running the following code also fixes the issue:

```nohighlight
    var canvas = document.createElement('canvas')
    var ctx = canvas.getContext('2d')
    ctx.clearRect(0, 0, canvas.width, canvas.height)
    var url = canvas.toDataURL('image/png')

```

That code isn’t touching babylon at all, so I suppose something magical may be going on - perhaps related to babylon listening for DOM events related to canvas elements, or similar.

Does anyone have any idea what might be going on? I never had the issue in `5.2`, so I suppose it’s related to a relatively recent update.

Thanks!

---

<div class="post-metadata">

**Author:** ![Deltakosh](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/deltakosh/32/26635_2.png) [@Deltakosh](https://forum.babylonjs.com/u/Deltakosh)\
**Post date:** [July 7, 2022, 3:24pm UTC](https://forum.babylonjs.com/t/strange-issue-in-latest-related-to-canvas-size-settings/31982/2 "2022-07-07T15:24:25Z")

</div>

As far as I know we are not listening to any canvas event ☹ so this may also be related to a browser issue?

Do you repro with Firefox for instance?

---

<div class="post-metadata">

**Author:** ![fenomas](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/fenomas/32/2309_2.png) [@fenomas](https://forum.babylonjs.com/u/fenomas)\
**Post date:** [July 7, 2022, 4:03pm UTC](https://forum.babylonjs.com/t/strange-issue-in-latest-related-to-canvas-size-settings/31982/3 "2022-07-07T16:03:32Z")

</div>

Hm, I’ve just tested and the issue doesn’t reproduce at all in Firefox/current, but it happens often in Chrome (mac). I guess possibly a timing issue with the state of the canvas at the time when Babylon initializes?

But it definitely wasn’t happening under Babylon 5.2.0 so I guess there are several things going on. I tried some random hacks - like waiting a few seconds between creating the canvas and initializing Babylon, but the issue still happens reliably.

Did anything change recently in Babylon, related to how the engine initializes with respect to the canvas element?

---

<div class="post-metadata">

**Author:** ![Deltakosh](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/deltakosh/32/26635_2.png) [@Deltakosh](https://forum.babylonjs.com/u/Deltakosh)\
**Post date:** [July 7, 2022, 5:09pm UTC](https://forum.babylonjs.com/t/strange-issue-in-latest-related-to-canvas-size-settings/31982/4 "2022-07-07T17:09:19Z")

</div>

Nothing that I can remember for a while. Initi phase is relatively stable. I even checked the blame page of our init code ☹

---

<div class="post-metadata">

**Author:** ![Deltakosh](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/deltakosh/32/26635_2.png) [@Deltakosh](https://forum.babylonjs.com/u/Deltakosh)\
**Post date:** [July 7, 2022, 5:11pm UTC](https://forum.babylonjs.com/t/strange-issue-in-latest-related-to-canvas-size-settings/31982/5 "2022-07-07T17:11:28Z")

</div>

See: [Babylon.js/packages/dev/core/src/Engines/thinEngine.ts at master · BabylonJS/Babylon.js (github.com)](https://github.com/BabylonJS/Babylon.js/blame/master/packages/dev/core/src/Engines/thinEngine.ts)

Only change is for the version string

---

<div class="post-metadata">

**Author:** ![fenomas](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/fenomas/32/2309_2.png) [@fenomas](https://forum.babylonjs.com/u/fenomas)\
**Post date:** [July 8, 2022, 4:43am UTC](https://forum.babylonjs.com/t/strange-issue-in-latest-related-to-canvas-size-settings/31982/6 "2022-07-08T04:43:15Z")

</div>

Hi DK, thanks for checking.

I tested further and I think this was a Chrome bug. I must have updated Babylon and Chrome around the same time, making it look like a Babylon issue.

Thanks!

---

<div class="post-metadata">

**Author:** ![Deltakosh](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/deltakosh/32/26635_2.png) [@Deltakosh](https://forum.babylonjs.com/u/Deltakosh)\
**Post date:** [July 8, 2022, 2:28pm UTC](https://forum.babylonjs.com/t/strange-issue-in-latest-related-to-canvas-size-settings/31982/7 "2022-07-08T14:28:27Z")

</div>

Ok thanks! I somehow prefer that ;D
