Skip to content

Commit

Permalink
[Fix] Improve handling of lost device on WebGL (#7121)
Browse files Browse the repository at this point in the history
Co-authored-by: Martin Valigursky <[email protected]>
  • Loading branch information
mvaligursky and Martin Valigursky committed Nov 19, 2024
1 parent fc34e35 commit 9dd6f45
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/platform/graphics/webgl/webgl-shader.js
Original file line number Diff line number Diff line change
Expand Up @@ -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, () => {
Expand All @@ -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);

Expand Down

0 comments on commit 9dd6f45

Please sign in to comment.