Skip to content

Commit

Permalink
RenderTarget.resize will now check the autoResize property before…
Browse files Browse the repository at this point in the history
… 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
  • Loading branch information
photonstorm committed Oct 10, 2024
1 parent 22bd585 commit 509de6a
Showing 1 changed file with 27 additions and 15 deletions.
42 changes: 27 additions & 15 deletions src/renderer/webgl/RenderTarget.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ var RenderTarget = new Class({
*/
this.forceClamp = forceClamp;

this.resize(width, height);
this.init(width, height);

if (autoResize)
{
Expand All @@ -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.
Expand Down Expand Up @@ -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
Expand All @@ -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;

Expand Down Expand Up @@ -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);
},

Expand Down

0 comments on commit 509de6a

Please sign in to comment.