From aed7147ad7df62aab0b10bc787e6aecc67aab79e Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Fri, 22 Nov 2019 15:58:54 -0500 Subject: [PATCH 1/2] Check whether context is lost before `gl.shaderSource(...)`. When context is lost most gl calls are no-ops but this one can throw. When a program cannot be created `draw(...)` needs to fail silently just like all gl calls. fix #8986 --- src/render/program.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/render/program.js b/src/render/program.js index c30109f4d15..76881c57bef 100644 --- a/src/render/program.js +++ b/src/render/program.js @@ -27,6 +27,7 @@ class Program { numAttributes: number; fixedUniforms: Us; binderUniforms: Array; + failedToCreate: boolean; constructor(context: Context, source: {fragmentSource: string, vertexSource: string}, @@ -44,12 +45,14 @@ class Program { const fragmentSource = defines.concat(prelude.fragmentSource, source.fragmentSource).join('\n'); const vertexSource = defines.concat(prelude.vertexSource, source.vertexSource).join('\n'); const fragmentShader = gl.createShader(gl.FRAGMENT_SHADER); + if (this.failedToCreate = gl.isContextLost()) return; gl.shaderSource(fragmentShader, fragmentSource); gl.compileShader(fragmentShader); assert(gl.getShaderParameter(fragmentShader, gl.COMPILE_STATUS), (gl.getShaderInfoLog(fragmentShader): any)); gl.attachShader(this.program, fragmentShader); const vertexShader = gl.createShader(gl.VERTEX_SHADER); + if (this.failedToCreate = gl.isContextLost()) return; gl.shaderSource(vertexShader, vertexSource); gl.compileShader(vertexShader); assert(gl.getShaderParameter(vertexShader, gl.COMPILE_STATUS), (gl.getShaderInfoLog(vertexShader): any)); @@ -110,6 +113,8 @@ class Program { const gl = context.gl; + if (this.failedToCreate) return; + context.program.set(this.program); context.setDepthMode(depthMode); context.setStencilMode(stencilMode); From 10360875746d16989829526fe93a6b704bb6ab67 Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Fri, 22 Nov 2019 16:05:49 -0500 Subject: [PATCH 2/2] fixup --- src/render/program.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/render/program.js b/src/render/program.js index 76881c57bef..141de24b93a 100644 --- a/src/render/program.js +++ b/src/render/program.js @@ -45,14 +45,20 @@ class Program { const fragmentSource = defines.concat(prelude.fragmentSource, source.fragmentSource).join('\n'); const vertexSource = defines.concat(prelude.vertexSource, source.vertexSource).join('\n'); const fragmentShader = gl.createShader(gl.FRAGMENT_SHADER); - if (this.failedToCreate = gl.isContextLost()) return; + if (gl.isContextLost()) { + this.failedToCreate = true; + return; + } gl.shaderSource(fragmentShader, fragmentSource); gl.compileShader(fragmentShader); assert(gl.getShaderParameter(fragmentShader, gl.COMPILE_STATUS), (gl.getShaderInfoLog(fragmentShader): any)); gl.attachShader(this.program, fragmentShader); const vertexShader = gl.createShader(gl.VERTEX_SHADER); - if (this.failedToCreate = gl.isContextLost()) return; + if (gl.isContextLost()) { + this.failedToCreate = true; + return; + } gl.shaderSource(vertexShader, vertexSource); gl.compileShader(vertexShader); assert(gl.getShaderParameter(vertexShader, gl.COMPILE_STATUS), (gl.getShaderInfoLog(vertexShader): any));