Skip to content

Commit

Permalink
VAO leak in Mesh and Graphics (#4893)
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanpopelyshev authored and bigtimebuddy committed May 5, 2018
1 parent cdd59d3 commit 728cc22
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/core/graphics/Graphics.js
Original file line number Diff line number Diff line change
Expand Up @@ -1200,11 +1200,11 @@ export default class Graphics extends Container
}

// 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();
}
}

Expand All @@ -1216,7 +1216,7 @@ export default class Graphics extends Container
this.graphicsData = null;

this.currentPath = null;
this._webgl = null;
this._webGL = null;
this._localBounds = null;
}

Expand Down
53 changes: 53 additions & 0 deletions src/mesh/Mesh.js
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,59 @@ export default class Mesh extends core.Container
{
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);
}
}

/**
Expand Down

0 comments on commit 728cc22

Please sign in to comment.