From 335b86f34289f71849d20226fb740b89a799b274 Mon Sep 17 00:00:00 2001 From: phoboslab Date: Sun, 1 Dec 2019 17:21:49 +0100 Subject: [PATCH] Attempt to cleanly free WebGL context --- src/webgl.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/webgl.js b/src/webgl.js index ab7b362c..e1c25eb5 100644 --- a/src/webgl.js +++ b/src/webgl.js @@ -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(); @@ -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 {