From af52004b76a603defbce99f5fd67e4c594844659 Mon Sep 17 00:00:00 2001 From: Martin Valigursky Date: Mon, 18 Sep 2023 12:46:17 +0100 Subject: [PATCH] When the context is lost, silently ignore failed shader compilation --- src/platform/graphics/webgl/webgl-shader.js | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/platform/graphics/webgl/webgl-shader.js b/src/platform/graphics/webgl/webgl-shader.js index a5506ff21e6..71cd54324ce 100644 --- a/src/platform/graphics/webgl/webgl-shader.js +++ b/src/platform/graphics/webgl/webgl-shader.js @@ -149,13 +149,18 @@ class WebglShader { if (this.glProgram) return; + // if the device is lost, silently ignore + const gl = device.gl; + if (gl.isContextLost()) { + return; + } + let startTime = 0; Debug.call(() => { this.compileDuration = 0; startTime = now(); }); - const gl = device.gl; const glProgram = gl.createProgram(); this.glProgram = glProgram; @@ -235,6 +240,11 @@ class WebglShader { glShader = gl.createShader(isVertexShader ? gl.VERTEX_SHADER : gl.FRAGMENT_SHADER); + // if the device is lost, silently ignore + if (!glShader && gl.isContextLost()) { + return glShader; + } + gl.shaderSource(glShader, src); gl.compileShader(glShader); @@ -268,11 +278,16 @@ class WebglShader { */ finalize(device, shader) { + // if the device is lost, silently ignore + const gl = device.gl; + if (gl.isContextLost()) { + return true; + } + // if the program wasn't linked yet (shader was not created in batch) if (!this.glProgram) this.link(device, shader); - const gl = device.gl; const glProgram = this.glProgram; const definition = shader.definition;