From 6cb7e007e2da56f52ea36acaa19c73a187de4864 Mon Sep 17 00:00:00 2001 From: "Mr.doob" Date: Fri, 20 May 2022 16:51:56 +0900 Subject: [PATCH] WebGLRenderer: Listen to webglcontextcreationerror event. --- src/renderers/WebGLRenderer.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/renderers/WebGLRenderer.js b/src/renderers/WebGLRenderer.js index 696d68a47266f4..4669da78fc01d5 100644 --- a/src/renderers/WebGLRenderer.js +++ b/src/renderers/WebGLRenderer.js @@ -252,6 +252,7 @@ function WebGLRenderer( parameters = {} ) { // event listeners must be registered before WebGL context is created, see #12753 _canvas.addEventListener( 'webglcontextlost', onContextLost, false ); _canvas.addEventListener( 'webglcontextrestored', onContextRestore, false ); + _canvas.addEventListener( 'webglcontextcreationerror', onContextCreationError, false ); if ( _gl === null ) { @@ -593,6 +594,7 @@ function WebGLRenderer( parameters = {} ) { _canvas.removeEventListener( 'webglcontextlost', onContextLost, false ); _canvas.removeEventListener( 'webglcontextrestored', onContextRestore, false ); + _canvas.removeEventListener( 'webglcontextcreationerror', onContextCreationError, false ); renderLists.dispose(); renderStates.dispose(); @@ -653,6 +655,12 @@ function WebGLRenderer( parameters = {} ) { } + function onContextCreationError( event ) { + + console.error( 'THREE.WebGLRenderer: A WebGL context could not be created. Reason: ', event.statusMessage ); + + } + function onMaterialDispose( event ) { const material = event.target;