fix: add null check for losing webgl context

This commit is contained in:
Jesse Mazzella 2023-11-29 15:57:21 -08:00
parent 97cb783c4b
commit 3cc0ecd900

View File

@ -154,15 +154,21 @@ DrawWebGL.prototype.initContext = function () {
DrawWebGL.prototype.destroy = function () {
// Lose the context and delete all associated resources
// https://developer.mozilla.org/en-US/docs/Web/API/WebGL_API/WebGL_best_practices#lose_contexts_eagerly
this.gl.getExtension('WEBGL_lose_context').loseContext();
if (this.gl.getSupportedExtensions().includes('WEBGL_lose_context')) {
this.gl.getExtension('WEBGL_lose_context').loseContext();
}
this.gl.deleteBuffer(this.buffer);
this.buffer = undefined;
this.gl.deleteProgram(this.program);
this.program = undefined;
this.gl.deleteShader(this.vertexShader);
this.vertexShader = undefined;
this.gl.deleteShader(this.fragmentShader);
this.fragmentShader = undefined;
this.gl = undefined;
this.stopListening();