Skip to content

Commit

Permalink
Attempt to cleanly free WebGL context
Browse files Browse the repository at this point in the history
  • Loading branch information
phoboslab committed Dec 1, 2019
1 parent 67888f5 commit 335b86f
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/webgl.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,15 @@ var WebGLRenderer = function(options) {
WebGLRenderer.prototype.destroy = function() {
var gl = this.gl;

gl.deleteTexture(this.textureY);
gl.deleteTexture(this.textureCb);
gl.deleteTexture(this.textureCr);
this.deleteTexture(gl.TEXTURE0, this.textureY);
this.deleteTexture(gl.TEXTURE1, this.textureCb);
this.deleteTexture(gl.TEXTURE2, this.textureCr);

gl.useProgram(null);
gl.deleteProgram(this.program);
gl.deleteProgram(this.loadingProgram);

gl.bindBuffer(gl.ARRAY_BUFFER, null);
gl.deleteBuffer(this.vertexBuffer);

gl.getExtension('WEBGL_lose_context').loseContext();
Expand Down Expand Up @@ -197,7 +199,14 @@ WebGLRenderer.prototype.updateTexture = function(unit, texture, w, h, data) {
gl.LUMINANCE, gl.UNSIGNED_BYTE, data
);
}
}
};

WebGLRenderer.prototype.deleteTexture = function(unit, texture) {
var gl = this.gl;
gl.activeTexture(unit);
gl.bindTexture(gl.TEXTURE_2D, null);
gl.deleteTexture(texture);
};

WebGLRenderer.IsSupported = function() {
try {
Expand Down

0 comments on commit 335b86f

Please sign in to comment.