Skip to content

Commit

Permalink
Catch lost context when creating the WebGL renderer; see phoboslab#392
Browse files Browse the repository at this point in the history
  • Loading branch information
phoboslab committed Sep 4, 2022
1 parent 3afb0e5 commit 72c87ba
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/webgl.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ var WebGLRenderer = function(options) {
throw new Error('Failed to get WebGL Context');
}

// WebGLRenderer.destroy() will explicitly lose the GL context. Calling
// .getContext('webgl') on a Canvas element whose GL context has previously
// been lost, will return an un-restored GL context. So we try to catch this
// case here and try restore the GL context.
if (this.gl.isContextLost()) {
this.gl.getExtension('WEBGL_lose_context').restoreContext();
}

this.canvas.addEventListener('webglcontextlost', this.handleContextLost.bind(this), false);
this.canvas.addEventListener('webglcontextrestored', this.handleContextRestored.bind(this), false);

Expand Down

0 comments on commit 72c87ba

Please sign in to comment.