The WebGLRenderingContext.isContextLost()
method returns a Boolean
indicating whether or not the WebGL context has been lost and must be re-established before rendering can resume.
Syntax
let isLost = gl.isContextLost();
Return value
A Boolean
which is true
if the context is lost, or false
if not.
Usage notes
There are several reasons why a WebGL context may be lost, making it necessary to re-establish the context before resuming rendering. Examples include:
- Two or more pages are using the GPU, but together place too high a demand on the GPU, so the browser tells the two contexts that they've lost the connection, then selects one of the two to restore access for.
- The user's computer has multiple graphics processors (such as a laptop with both mobile and desktop class GPUs, the former used primarily when on battery power), and the user or system decides to switch GPUs. In this case, all contexts are lost, then restored after switching GPUs.
- Another page running in the user's browser performs an operation using the GPU that takes too long, causing hte browser to decide to reset the GPU in order to break the stall. This would cause every WebGL context to be lost throughout the entire browser.
- The user updates their graphics driver on an operating system that allows graphics drivers to be updated without restarting the system.
Examples
For example, when checking for program linking success, you could also check if the context is not lost:
gl.linkProgram(program); if (!gl.getProgramParameter(program, gl.LINK_STATUS) && !gl.isContextLost()) { var info = gl.getProgramInfoLog(program); console.log('Error linking program:\n' + info); }
Specifications
Specification | Status | Comment |
---|---|---|
WebGL 1.0 The definition of 'WebGLRenderingContext.isContextLost' in that specification. |
Recommendation | Initial definition. |
Browser compatibility
The compatibility table in this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
Desktop | Mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
isContextLost | Chrome Full support 9 | Edge Full support 12 | Firefox Full support 4 | IE Full support 11 | Opera Full support 12 | Safari Full support 5.1 | WebView Android Full support Yes | Chrome Android Full support 25 | Firefox Android Full support Yes | Opera Android Full support 12 | Safari iOS Full support 8 | Samsung Internet Android Full support 1.5 |
Legend
- Full support
- Full support
See also
- The
WebGLContextEvent
signals changes in the context state. - Handling lost context in WebGL: Khronos WebGL wiki