From 8892f46a8306be120c34121f6618104d2d87165c Mon Sep 17 00:00:00 2001 From: photonstorm Date: Wed, 11 Feb 2015 21:02:15 +0000 Subject: [PATCH] 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) --- README.md | 1 + src/core/Game.js | 27 ++--------------------- src/pixi/renderers/webgl/WebGLRenderer.js | 7 ++++-- 3 files changed, 8 insertions(+), 27 deletions(-) diff --git a/README.md b/README.md index 6b14c80f1..3640ce1aa 100644 --- a/README.md +++ b/README.md @@ -151,6 +151,7 @@ Thanks to @pnstickne for vast majority of this update. * 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) * 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. * Phaser.Ellipse.contains is now working again (thanks @spayton) +* 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) For changes in previous releases please see the extensive [Version History](https://github.com/photonstorm/phaser/blob/master/CHANGELOG.md). diff --git a/src/core/Game.js b/src/core/Game.js index a159aa29b..4d2c11753 100644 --- a/src/core/Game.js +++ b/src/core/Game.js @@ -956,31 +956,8 @@ Phaser.Game.prototype = { this.world = null; this.isBooted = false; - if (this.renderType === Phaser.WEBGL) - { - PIXI.glContexts[this.renderer.glContextId] = null; - - this.renderer.projection = null; - this.renderer.offset = null; - - this.renderer.shaderManager.destroy(); - this.renderer.spriteBatch.destroy(); - this.renderer.maskManager.destroy(); - this.renderer.filterManager.destroy(); - - this.renderer.shaderManager = null; - this.renderer.spriteBatch = null; - this.renderer.maskManager = null; - this.renderer.filterManager = null; - - this.renderer.gl = null; - this.renderer.renderSession = null; - Phaser.Canvas.removeFromDOM(this.canvas); - } - else - { - this.renderer.destroy(true); - } + this.renderer.destroy(false); + Phaser.Canvas.removeFromDOM(this.canvas); Phaser.GAMES[this.id] = null; diff --git a/src/pixi/renderers/webgl/WebGLRenderer.js b/src/pixi/renderers/webgl/WebGLRenderer.js index d6c458c66..44b2292c6 100644 --- a/src/pixi/renderers/webgl/WebGLRenderer.js +++ b/src/pixi/renderers/webgl/WebGLRenderer.js @@ -248,7 +248,7 @@ PIXI.WebGLRenderer.prototype.initContext = function() throw new Error('This browser does not support webGL. Try using the canvas renderer'); } - this.glContextId = gl.id = PIXI.WebGLRenderer.glContextId ++; + this.glContextId = gl.id = PIXI.WebGLRenderer.glContextId++; PIXI.glContexts[this.glContextId] = gl; @@ -502,7 +502,6 @@ PIXI.WebGLRenderer.prototype.destroy = function() this.projection = null; this.offset = null; - // time to create the render managers! each one focuses on managine a state in webGL this.shaderManager.destroy(); this.spriteBatch.destroy(); this.maskManager.destroy(); @@ -515,6 +514,10 @@ PIXI.WebGLRenderer.prototype.destroy = function() this.gl = null; this.renderSession = null; + + PIXI.instances[this.glContextId] = null; + + PIXI.WebGLRenderer.glContextId--; }; /**