Skip to content

Commit

Permalink
Check whether context is lost before gl.shaderSource(...).
Browse files Browse the repository at this point in the history
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
  • Loading branch information
ansis committed Nov 22, 2019
1 parent 2eb6fd6 commit aed7147
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/render/program.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class Program<Us: UniformBindings> {
numAttributes: number;
fixedUniforms: Us;
binderUniforms: Array<BinderUniform>;
failedToCreate: boolean;

constructor(context: Context,
source: {fragmentSource: string, vertexSource: string},
Expand All @@ -44,12 +45,14 @@ class Program<Us: UniformBindings> {
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));
Expand Down Expand Up @@ -110,6 +113,8 @@ class Program<Us: UniformBindings> {

const gl = context.gl;

if (this.failedToCreate) return;

context.program.set(this.program);
context.setDepthMode(depthMode);
context.setStencilMode(stencilMode);
Expand Down

0 comments on commit aed7147

Please sign in to comment.