From 72e2857882686eb1e86a8a7a901f54751b05fc7d Mon Sep 17 00:00:00 2001 From: Richard Davey Date: Thu, 10 Oct 2024 16:54:46 +0100 Subject: [PATCH] The `EXPAND` Scale Mode would cause the error "Framebuffer status: Incomplete Attachment" under WebGL if the Phaser game loaded into an iframe or element with a size of 0 on either axis, such as when you load the game into a 0x0 iframe before expanding it. It now protects against divide by zero errors. --- src/scale/ScaleManager.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/scale/ScaleManager.js b/src/scale/ScaleManager.js index 496eb46a5..1f0d39605 100644 --- a/src/scale/ScaleManager.js +++ b/src/scale/ScaleManager.js @@ -431,12 +431,14 @@ var ScaleManager = new Class({ this.fullscreen = game.device.fullscreen; - if ((this.scaleMode !== CONST.SCALE_MODE.RESIZE) && (this.scaleMode !== CONST.SCALE_MODE.EXPAND)) + var scaleMode = this.scaleMode; + + if (scaleMode !== CONST.SCALE_MODE.RESIZE && scaleMode !== CONST.SCALE_MODE.EXPAND) { - this.displaySize.setAspectMode(this.scaleMode); + this.displaySize.setAspectMode(scaleMode); } - if (this.scaleMode === CONST.SCALE_MODE.NONE) + if (scaleMode === CONST.SCALE_MODE.NONE) { this.resize(this.width, this.height); } @@ -1104,18 +1106,16 @@ var ScaleManager = new Class({ style.width = styleWidth + 'px'; style.height = styleHeight + 'px'; - // Expand canvas size to fit game size's width or height var scaleX = this.parentSize.width / baseWidth; - var scaleY = this.parentSize.height / baseHeight; - if (scaleX < scaleY) + if (scaleX < scaleY && scaleX !== 0) { this.baseSize.setSize(baseWidth, this.parentSize.height / scaleX); } - else + else if (scaleY !== 0) { this.baseSize.setSize(this.displaySize.width / scaleY, baseHeight); }