Skip to content

Commit

Permalink
Make sure animationLoop's onError catches context creation errors (#1419
Browse files Browse the repository at this point in the history
)
  • Loading branch information
Pessimistress committed Dec 8, 2020
1 parent 18d75a2 commit e03ef9c
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions modules/gltools/src/context/context.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,8 @@ function createBrowserContext(canvas, options) {
const {onError} = options;

// Try to extract any extra information about why context creation failed
const onCreateError = error => onError(`WebGL context: ${error.statusMessage || 'error'}`);
let errorMessage = null;
const onCreateError = error => (errorMessage = error.statusMessage || errorMessage);
canvas.addEventListener('webglcontextcreationerror', onCreateError, false);

const {webgl1 = true, webgl2 = true} = options;
Expand All @@ -194,7 +195,10 @@ function createBrowserContext(canvas, options) {
canvas.removeEventListener('webglcontextcreationerror', onCreateError, false);

if (!gl) {
return onError(`Failed to create ${webgl2 && !webgl1 ? 'WebGL2' : 'WebGL'} context`);
return onError(
`Failed to create ${webgl2 && !webgl1 ? 'WebGL2' : 'WebGL'} context: ${errorMessage ||
'Unknown error'}`
);
}

return gl;
Expand Down

0 comments on commit e03ef9c

Please sign in to comment.