Skip to content

Commit

Permalink
When the context is lost, silently ignore failed shader compilation (#…
Browse files Browse the repository at this point in the history
…5644)

Co-authored-by: Martin Valigursky <[email protected]>
  • Loading branch information
mvaligursky and Martin Valigursky committed Sep 18, 2023
1 parent 162d363 commit bdf8eac
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/platform/graphics/webgl/webgl-shader.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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;

Expand Down

0 comments on commit bdf8eac

Please sign in to comment.