Skip to content

Commit 2da9c84

Browse files
mvaligurskyMartin Valigursky
andauthored
[Fix] Improve handling of lost device on WebGL (playcanvas#7121)
Co-authored-by: Martin Valigursky <mvaligursky@snapchat.com>
1 parent 11a9f06 commit 2da9c84

1 file changed

Lines changed: 6 additions & 6 deletions

File tree

src/platform/graphics/webgl/webgl-shader.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -192,12 +192,17 @@ class WebglShader {
192192
* @param {string} src - The shader source code.
193193
* @param {boolean} isVertexShader - True if the shader is a vertex shader, false if it is a
194194
* fragment shader.
195-
* @returns {WebGLShader} The compiled shader.
195+
* @returns {WebGLShader|null} The compiled shader, or null if the device is lost.
196196
* @private
197197
*/
198198
_compileShaderSource(device, src, isVertexShader) {
199199
const gl = device.gl;
200200

201+
// if the device is lost, silently ignore
202+
if (gl.isContextLost()) {
203+
return null;
204+
}
205+
201206
// device cache for current device, containing cache of compiled shaders
202207
const shaderDeviceCache = isVertexShader ? _vertexShaderCache : _fragmentShaderCache;
203208
const shaderCache = shaderDeviceCache.get(device, () => {
@@ -218,11 +223,6 @@ class WebglShader {
218223

219224
glShader = gl.createShader(isVertexShader ? gl.VERTEX_SHADER : gl.FRAGMENT_SHADER);
220225

221-
// if the device is lost, silently ignore
222-
if (!glShader && gl.isContextLost()) {
223-
return glShader;
224-
}
225-
226226
gl.shaderSource(glShader, src);
227227
gl.compileShader(glShader);
228228

0 commit comments

Comments
 (0)