From dbd9ee31a2a8fcc8a4fb12db79f8823054570cb3 Mon Sep 17 00:00:00 2001 From: Vincent JAILLOT Date: Thu, 8 Dec 2022 10:46:08 +0100 Subject: [PATCH] fix(view): fix view resize when width or height is 0 --- src/Core/View.js | 11 +++++++++-- src/Renderer/Camera.js | 10 +++++++--- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/Core/View.js b/src/Core/View.js index 20e3ddbed3..c2cbb9edf4 100644 --- a/src/Core/View.js +++ b/src/Core/View.js @@ -1088,6 +1088,11 @@ class View extends THREE.EventDispatcher { * the viewer with. By default it is the `clientHeight` of the `viewerDiv`. */ resize(width, height) { + if (width < 0 || height < 0) { + console.warn(`Trying to resize the View with negative height (${height}) or width (${width}). Skipping resize.`); + return; + } + if (width == undefined) { width = this.domElement.clientWidth; } @@ -1098,8 +1103,10 @@ class View extends THREE.EventDispatcher { this.#fullSizeDepthBuffer = new Uint8Array(4 * width * height); this.mainLoop.gfxEngine.onWindowResize(width, height); - this.camera.resize(width, height); - this.notifyChange(this.camera.camera3D); + if (width !== 0 && height !== 0) { + this.camera.resize(width, height); + this.notifyChange(this.camera.camera3D); + } } } diff --git a/src/Renderer/Camera.js b/src/Renderer/Camera.js index efc7302921..a580973376 100644 --- a/src/Renderer/Camera.js +++ b/src/Renderer/Camera.js @@ -139,12 +139,16 @@ class Camera { } /** - * Resize the camera to a given width and height + * Resize the camera to a given width and height. * - * @param {number} width The width to resize the camera to. - * @param {number} height The height to resize the camera to. + * @param {number} width The width to resize the camera to. Must be strictly positive, won't resize otherwise. + * @param {number} height The height to resize the camera to. Must be strictly positive, won't resize otherwise. */ resize(width, height) { + if (!width || width <= 0 || !height || height <= 0) { + console.warn(`Trying to resize the Camera with invalid height (${height}) or width (${width}). Skipping resize.`); + return; + } const ratio = width / height; if (this.camera3D.aspect !== ratio) { if (this.camera3D.isOrthographicCamera) {