From 509de6ae51d5d1ffa6fefa0bf7e46720f7e464db Mon Sep 17 00:00:00 2001 From: Richard Davey Date: Thu, 10 Oct 2024 18:37:00 +0100 Subject: [PATCH] `RenderTarget.resize` will now check the `autoResize` property before applying the change. Textures that have been locked to a fixed size, such as FX POT buffers, will no longer be resized to the full canvas dimensions, causing Out of Memory errors on some mobile devices. Fix #6914 --- src/renderer/webgl/RenderTarget.js | 42 +++++++++++++++++++----------- 1 file changed, 27 insertions(+), 15 deletions(-) diff --git a/src/renderer/webgl/RenderTarget.js b/src/renderer/webgl/RenderTarget.js index 3bcb9797c0..d203d3f7f6 100644 --- a/src/renderer/webgl/RenderTarget.js +++ b/src/renderer/webgl/RenderTarget.js @@ -160,7 +160,7 @@ var RenderTarget = new Class({ */ this.forceClamp = forceClamp; - this.resize(width, height); + this.init(width, height); if (autoResize) { @@ -173,6 +173,28 @@ var RenderTarget = new Class({ } }, + /** + * Sets up this Render Target to the given width and height, creating a new + * frame buffer and texture. This method is called automatically by the constructor + * and at no other time. + * + * @method Phaser.Renderer.WebGL.RenderTarget#init + * @since 3.86.0 + * + * @param {number} width - The new width of this Render Target. + * @param {number} height - The new height of this Render Target. + */ + init: function (width, height) + { + var renderer = this.renderer; + + this.texture = renderer.createTextureFromSource(null, width, height, this.minFilter, this.forceClamp); + this.framebuffer = renderer.createFramebuffer(width, height, this.texture, this.hasDepthBuffer); + + this.width = width; + this.height = height; + }, + /** * Sets if this Render Target should automatically resize when the WebGL Renderer * emits a resize event. @@ -210,9 +232,6 @@ var RenderTarget = new Class({ * them using the new sizes. * * This method is called automatically by the pipeline during its resize handler. - * - * Previous to Phaser v3.85 this method would only run if `autoResize` was `true`, - * it will now run regardless. * * @method Phaser.Renderer.WebGL.RenderTarget#resize * @since 3.50.0 @@ -224,7 +243,7 @@ var RenderTarget = new Class({ */ resize: function (width, height) { - if (this.willResize(width, height)) + if (this.autoResize && this.willResize(width, height)) { var renderer = this.renderer; @@ -264,16 +283,9 @@ var RenderTarget = new Class({ width = Math.round(width * this.scale); height = Math.round(height * this.scale); - if (width <= 0) - { - width = 1; - } - - if (height <= 0) - { - height = 1; - } - + width = Math.max(width, 1); + height = Math.max(height, 1); + return (width !== this.width || height !== this.height); },