diff --git a/src/platform/graphics/webgl/webgl-shader.js b/src/platform/graphics/webgl/webgl-shader.js index bc41dee5ec5..1ccab752e93 100644 --- a/src/platform/graphics/webgl/webgl-shader.js +++ b/src/platform/graphics/webgl/webgl-shader.js @@ -190,12 +190,17 @@ class WebglShader { * @param {string} src - The shader source code. * @param {boolean} isVertexShader - True if the shader is a vertex shader, false if it is a * fragment shader. - * @returns {WebGLShader} The compiled shader. + * @returns {WebGLShader|null} The compiled shader, or null if the device is lost. * @private */ _compileShaderSource(device, src, isVertexShader) { const gl = device.gl; + // if the device is lost, silently ignore + if (gl.isContextLost()) { + return null; + } + // device cache for current device, containing cache of compiled shaders const shaderDeviceCache = isVertexShader ? _vertexShaderCache : _fragmentShaderCache; const shaderCache = shaderDeviceCache.get(device, () => { @@ -216,11 +221,6 @@ 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);