Skip to content

Commit 8892f46

Browse files
committed
PIXI.WebGLRenderer.destroy has been fixed to decrement the glContextId and remove it from the PIXI.instances global. Game.destroy now hooks into this. This now means that you can now delete and create your Phaser game over and over without it crashing WebGL after the 4th attempt (phaserjs#1260)
1 parent b68c307 commit 8892f46

3 files changed

Lines changed: 8 additions & 27 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ Thanks to @pnstickne for vast majority of this update.
151151
* Pointer.stop would call `event.preventDefault` if `Pointer._stateReset` was `true`, which is always `true` after a State has changed and before Pointer.start has been called. However this broken interacting with DOM elements in the case where the State changes and you immediately try to use the DOM element without first having clicked on the Phaser game. An additional guard was added so `preventDefault` will now only be called if both `_stateReste` and `Pointer.withinGame` are true (thanks @satan6 #1509)
152152
* Group.forEach (and many other Group methods) now uses the `children.length` value directly instead of caching it, which both helps performance and stops the loop from breaking should you remove a Group child in the invoked callback.
153153
* Phaser.Ellipse.contains is now working again (thanks @spayton)
154+
* PIXI.WebGLRenderer.destroy has been fixed to decrement the `glContextId` and remove it from the PIXI.instances global. `Game.destroy` now hooks into this. This now means that you can now delete and create your Phaser game over and over without it crashing WebGL after the 4th attempt (#1260)
154155

155156
For changes in previous releases please see the extensive [Version History](https://github.com/photonstorm/phaser/blob/master/CHANGELOG.md).
156157

src/core/Game.js

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -956,31 +956,8 @@ Phaser.Game.prototype = {
956956
this.world = null;
957957
this.isBooted = false;
958958

959-
if (this.renderType === Phaser.WEBGL)
960-
{
961-
PIXI.glContexts[this.renderer.glContextId] = null;
962-
963-
this.renderer.projection = null;
964-
this.renderer.offset = null;
965-
966-
this.renderer.shaderManager.destroy();
967-
this.renderer.spriteBatch.destroy();
968-
this.renderer.maskManager.destroy();
969-
this.renderer.filterManager.destroy();
970-
971-
this.renderer.shaderManager = null;
972-
this.renderer.spriteBatch = null;
973-
this.renderer.maskManager = null;
974-
this.renderer.filterManager = null;
975-
976-
this.renderer.gl = null;
977-
this.renderer.renderSession = null;
978-
Phaser.Canvas.removeFromDOM(this.canvas);
979-
}
980-
else
981-
{
982-
this.renderer.destroy(true);
983-
}
959+
this.renderer.destroy(false);
960+
Phaser.Canvas.removeFromDOM(this.canvas);
984961

985962
Phaser.GAMES[this.id] = null;
986963

src/pixi/renderers/webgl/WebGLRenderer.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ PIXI.WebGLRenderer.prototype.initContext = function()
248248
throw new Error('This browser does not support webGL. Try using the canvas renderer');
249249
}
250250

251-
this.glContextId = gl.id = PIXI.WebGLRenderer.glContextId ++;
251+
this.glContextId = gl.id = PIXI.WebGLRenderer.glContextId++;
252252

253253
PIXI.glContexts[this.glContextId] = gl;
254254

@@ -502,7 +502,6 @@ PIXI.WebGLRenderer.prototype.destroy = function()
502502
this.projection = null;
503503
this.offset = null;
504504

505-
// time to create the render managers! each one focuses on managine a state in webGL
506505
this.shaderManager.destroy();
507506
this.spriteBatch.destroy();
508507
this.maskManager.destroy();
@@ -515,6 +514,10 @@ PIXI.WebGLRenderer.prototype.destroy = function()
515514

516515
this.gl = null;
517516
this.renderSession = null;
517+
518+
PIXI.instances[this.glContextId] = null;
519+
520+
PIXI.WebGLRenderer.glContextId--;
518521
};
519522

520523
/**

0 commit comments

Comments
 (0)