diff --git a/src/core/graphics/Graphics.js b/src/core/graphics/Graphics.js index 6dae5c1..3949428 100644 --- a/src/core/graphics/Graphics.js +++ b/src/core/graphics/Graphics.js @@ -1160,10 +1160,18 @@ Graphics.prototype.destroy = function () { Container.prototype.destroy.apply(this, arguments); + // destroy each of the GraphicsData objects for (var i = 0; i < this.graphicsData.length; ++i) { this.graphicsData[i].destroy(); } + // for each webgl data entry, destroy the WebGLGraphicsData + for (var id in this._webgl) { + for (var j = 0; j < this._webgl[id].data.length; ++j) { + this._webgl[id].data[j].destroy(); + } + } + this.graphicsData = null; this.currentPath = null; diff --git a/src/core/graphics/Graphics.js b/src/core/graphics/Graphics.js index 6dae5c1..3949428 100644 --- a/src/core/graphics/Graphics.js +++ b/src/core/graphics/Graphics.js @@ -1160,10 +1160,18 @@ Graphics.prototype.destroy = function () { Container.prototype.destroy.apply(this, arguments); + // destroy each of the GraphicsData objects for (var i = 0; i < this.graphicsData.length; ++i) { this.graphicsData[i].destroy(); } + // for each webgl data entry, destroy the WebGLGraphicsData + for (var id in this._webgl) { + for (var j = 0; j < this._webgl[id].data.length; ++j) { + this._webgl[id].data[j].destroy(); + } + } + this.graphicsData = null; this.currentPath = null; diff --git a/src/core/graphics/webgl/GraphicsRenderer.js b/src/core/graphics/webgl/GraphicsRenderer.js index e3a5da7..6bbafb4 100644 --- a/src/core/graphics/webgl/GraphicsRenderer.js +++ b/src/core/graphics/webgl/GraphicsRenderer.js @@ -48,6 +48,10 @@ GraphicsRenderer.prototype.destroy = function () { ObjectRenderer.prototype.destroy.call(this); + for (var i = 0; i < this.graphicsDataPool.length; ++i) { + this.graphicsDataPool[i].destroy(); + } + this.graphicsDataPool = null; }; @@ -151,7 +155,7 @@ { graphics.clearDirty = false; - // lop through and return all the webGLDatas to the object pool so than can be reused later on + // loop through and return all the webGLDatas to the object pool so than can be reused later on for (i = 0; i < webGL.data.length; i++) { var graphicsData = webGL.data[i]; diff --git a/src/core/graphics/Graphics.js b/src/core/graphics/Graphics.js index 6dae5c1..3949428 100644 --- a/src/core/graphics/Graphics.js +++ b/src/core/graphics/Graphics.js @@ -1160,10 +1160,18 @@ Graphics.prototype.destroy = function () { Container.prototype.destroy.apply(this, arguments); + // destroy each of the GraphicsData objects for (var i = 0; i < this.graphicsData.length; ++i) { this.graphicsData[i].destroy(); } + // for each webgl data entry, destroy the WebGLGraphicsData + for (var id in this._webgl) { + for (var j = 0; j < this._webgl[id].data.length; ++j) { + this._webgl[id].data[j].destroy(); + } + } + this.graphicsData = null; this.currentPath = null; diff --git a/src/core/graphics/webgl/GraphicsRenderer.js b/src/core/graphics/webgl/GraphicsRenderer.js index e3a5da7..6bbafb4 100644 --- a/src/core/graphics/webgl/GraphicsRenderer.js +++ b/src/core/graphics/webgl/GraphicsRenderer.js @@ -48,6 +48,10 @@ GraphicsRenderer.prototype.destroy = function () { ObjectRenderer.prototype.destroy.call(this); + for (var i = 0; i < this.graphicsDataPool.length; ++i) { + this.graphicsDataPool[i].destroy(); + } + this.graphicsDataPool = null; }; @@ -151,7 +155,7 @@ { graphics.clearDirty = false; - // lop through and return all the webGLDatas to the object pool so than can be reused later on + // loop through and return all the webGLDatas to the object pool so than can be reused later on for (i = 0; i < webGL.data.length; i++) { var graphicsData = webGL.data[i]; diff --git a/src/core/graphics/webgl/WebGLGraphicsData.js b/src/core/graphics/webgl/WebGLGraphicsData.js index 7e2022b..8b342d5 100644 --- a/src/core/graphics/webgl/WebGLGraphicsData.js +++ b/src/core/graphics/webgl/WebGLGraphicsData.js @@ -62,6 +62,9 @@ * @member {boolean} */ this.dirty = true; + + this.glPoints = null; + this.glIndices = null; } WebGLGraphicsData.prototype.constructor = WebGLGraphicsData; @@ -94,3 +97,19 @@ this.dirty = false; }; + +WebGLGraphicsData.prototype.destroy = function () { + this.gl = null; + this.color = null; + this.points = null; + this.indices = null; + + this.gl.deleteBuffer(this.buffer); + this.gl.deleteBuffer(this.indexBuffer); + + this.buffer = null; + this.indexBuffer = null; + + this.glPoints = null; + this.glIndices = null; +};