Skip to content

Commit 609b38c

Browse files
committed
BitmapData.update causes a snowballing memory leak under WebGL due to a Context.getImageData call. BitmapData.clear used to call update automatically but no longer does. This resolves the issue of the Debug class causing excessive memory build-up in Chrome. Firefox and IE were unaffected (thanks @kingjerod phaserjs#2208)
1 parent 3d1306d commit 609b38c

2 files changed

Lines changed: 6 additions & 2 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,7 @@ If you are an exceptional JavaScript developer and would like to join the Phaser
280280

281281
* Buttons (or any Sprites) that don't have a texture, but have children, would incorrectly render the children under WebGL due to the baseTexture.skipRender property (thanks @puzzud #2141)
282282
* TilemapParser accidentally redeclared `i` when parsing the ImageCollections which would cause an infinite loop (thanks DanHett)
283+
* BitmapData.update causes a snowballing memory leak under WebGL due to a Context.getImageData call. BitmapData.clear used to call update automatically but no longer does. This resolves the issue of the Debug class causing excessive memory build-up in Chrome. Firefox and IE were unaffected (thanks @kingjerod #2208)
283284

284285
### Pixi Updates
285286

src/gameobjects/BitmapData.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,9 @@ Phaser.BitmapData.prototype = {
441441
* You can optionally define the area to clear.
442442
* If the arguments are left empty it will clear the entire canvas.
443443
*
444+
* You may need to call BitmapData.update after this in order to clear out the pixel data,
445+
* but Phaser will not do this automatically for you.
446+
*
444447
* @method Phaser.BitmapData#clear
445448
* @param {number} [x=0] - The x coordinate of the top-left of the area to clear.
446449
* @param {number} [y=0] - The y coordinate of the top-left of the area to clear.
@@ -457,8 +460,6 @@ Phaser.BitmapData.prototype = {
457460

458461
this.context.clearRect(x, y, width, height);
459462

460-
this.update();
461-
462463
this.dirty = true;
463464

464465
return this;
@@ -567,6 +568,8 @@ Phaser.BitmapData.prototype = {
567568
* It then re-builds the ArrayBuffer, the data Uint8ClampedArray reference and the pixels Int32Array.
568569
* If not given the dimensions defaults to the full size of the context.
569570
*
571+
* Warning: This is a very expensive operation, so use it sparingly.
572+
*
570573
* @method Phaser.BitmapData#update
571574
* @param {number} [x=0] - The x coordinate of the top-left of the image data area to grab from.
572575
* @param {number} [y=0] - The y coordinate of the top-left of the image data area to grab from.

0 commit comments

Comments
 (0)