diff --git a/src/core/graphics/Graphics.js b/src/core/graphics/Graphics.js index 1f66403..fa194b8 100644 --- a/src/core/graphics/Graphics.js +++ b/src/core/graphics/Graphics.js @@ -1200,11 +1200,11 @@ } // for each webgl data entry, destroy the WebGLGraphicsData - for (const id in this._webgl) + for (const id in this._webGL) { - for (let j = 0; j < this._webgl[id].data.length; ++j) + for (let j = 0; j < this._webGL[id].data.length; ++j) { - this._webgl[id].data[j].destroy(); + this._webGL[id].data[j].destroy(); } } @@ -1216,7 +1216,7 @@ this.graphicsData = null; this.currentPath = null; - this._webgl = null; + this._webGL = null; this._localBounds = null; } diff --git a/src/core/graphics/Graphics.js b/src/core/graphics/Graphics.js index 1f66403..fa194b8 100644 --- a/src/core/graphics/Graphics.js +++ b/src/core/graphics/Graphics.js @@ -1200,11 +1200,11 @@ } // for each webgl data entry, destroy the WebGLGraphicsData - for (const id in this._webgl) + for (const id in this._webGL) { - for (let j = 0; j < this._webgl[id].data.length; ++j) + for (let j = 0; j < this._webGL[id].data.length; ++j) { - this._webgl[id].data[j].destroy(); + this._webGL[id].data[j].destroy(); } } @@ -1216,7 +1216,7 @@ this.graphicsData = null; this.currentPath = null; - this._webgl = null; + this._webGL = null; this._localBounds = null; } diff --git a/src/mesh/Mesh.js b/src/mesh/Mesh.js index 25659cf..4ed6a27 100644 --- a/src/mesh/Mesh.js +++ b/src/mesh/Mesh.js @@ -326,6 +326,59 @@ { this.tintRgb = core.utils.hex2rgb(value, this.tintRgb); } + + /** + * Destroys the Mesh object. + * + * @param {object|boolean} [options] - Options parameter. A boolean will act as if all + * options have been set to that value + * @param {boolean} [options.children=false] - if set to true, all the children will have + * their destroy method called as well. 'options' will be passed on to those calls. + * @param {boolean} [options.texture=false] - Only used for child Sprites if options.children is set to true + * Should it destroy the texture of the child sprite + * @param {boolean} [options.baseTexture=false] - Only used for child Sprites if options.children is set to true + * Should it destroy the base texture of the child sprite + */ + destroy(options) + { + // for each webgl data entry, destroy the WebGLGraphicsData + for (const id in this._glDatas) + { + const data = this._glDatas[id]; + + if (data.destroy) + { + data.destroy(); + } + else + { + if (data.vertexBuffer) + { + data.vertexBuffer.destroy(); + data.vertexBuffer = null; + } + if (data.indexBuffer) + { + data.indexBuffer.destroy(); + data.indexBuffer = null; + } + if (data.uvBuffer) + { + data.uvBuffer.destroy(); + data.uvBuffer = null; + } + if (data.vao) + { + data.vao.destroy(); + data.vao = null; + } + } + } + + this._glDatas = null; + + super.destroy(options); + } } /**