diff --git a/packages/graphics/src/Graphics.js b/packages/graphics/src/Graphics.js index beddc46..ad7ada4 100644 --- a/packages/graphics/src/Graphics.js +++ b/packages/graphics/src/Graphics.js @@ -1143,11 +1143,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(); } } @@ -1159,7 +1159,7 @@ this.graphicsData = null; this.currentPath = null; - this._webgl = null; + this._webGL = null; this._localBounds = null; } } diff --git a/packages/graphics/src/Graphics.js b/packages/graphics/src/Graphics.js index beddc46..ad7ada4 100644 --- a/packages/graphics/src/Graphics.js +++ b/packages/graphics/src/Graphics.js @@ -1143,11 +1143,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(); } } @@ -1159,7 +1159,7 @@ this.graphicsData = null; this.currentPath = null; - this._webgl = null; + this._webGL = null; this._localBounds = null; } } diff --git a/packages/mesh/src/RawMesh.js b/packages/mesh/src/RawMesh.js index 63c3125..7297e94 100644 --- a/packages/mesh/src/RawMesh.js +++ b/packages/mesh/src/RawMesh.js @@ -160,4 +160,61 @@ return false; } + + /** + * Destroys the RawMesh 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; + + this.geometry = null; + this.shader = null; + this.state = null; + + super.destroy(options); + } }