Eagerly lose WebGL context on DrawWebGL.destroy() (#7080)

* test default for preserveDrawingBuffer
* fix: delete WebGL resources on destroy
* fix: eagerly lose WebGL contexts on destroy
- Recommended by Mozilla's [WebGL best practices]-(https://developer.mozilla.org/en-US/docs/Web/API/WebGL_API/WebGL_best_practices#lose_contexts_eagerly).

Co-authored-by: Jesse Mazzella <jesse.d.mazzella@nasa.gov>
Co-authored-by: Jesse Mazzella <ozyx@users.noreply.github.com>
This commit is contained in:
David Tsay 2023-10-03 12:33:51 -07:00 committed by GitHub
parent d973140906
commit d53d8d562e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -152,9 +152,22 @@ 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();
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();
this.canvas = undefined;
this.overlay = undefined;
this.stopListening();
};
// Convert from logical to physical x coordinates