Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When the context is lost, silently ignore failed shader compilation #5644

Merged
merged 1 commit into from
Sep 18, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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