Any experiences handling lost context in WebGL?

848 views
Skip to first unread message

Lindsay Kay

unread,
Mar 31, 2012, 2:33:15 PM3/31/12
to webgl-d...@googlegroups.com
Hi all,

just wondering if any of the WebGL frameworks out there are handling "webglcontextlost" and "webglcontextrestored" events for graceful recovery..?

Applications built on SceneJS occasionally get errors like "invalid framebuffer", so I'd like to see if it's practical to actually transparently encapsulate that event handling within SceneJS, rather than just reboot the application layer.

PS. I've read the excellent page over at http://www.khronos.org/webgl/wiki/HandlingContextLost, but would appreciate any experiences people can share on how they've handled these events in their frameworks or apps.

cheers,
Lindsay Kay




Benoit Jacob

unread,
Mar 31, 2012, 2:52:04 PM3/31/12
to webgl-d...@googlegroups.com
Hey, great topic.

I would just like to emphasize, as the wiki page you linked to
explains, that you can test lost context events by using the
WEBGL_lose_context extension (currently with WEBKIT_ and MOZ_ vendor
prefixes).

FWIW, we have definite plans to start generating context losses in
more cases than we currently do. Currently, aside from the
lose_context extension, you only get a WebGL context loss when the
underlying OpenGL context is lost (either through the ARB_robustness
watchdog timer, or EGL_CONTEXT_LOST on mobile devices). We ( =
Mozilla) plan to lose contexts in increasingly many cases:
- when a given page creates too many WebGL contexts (where too many
it at least 8), we'll probably start losing the least recently used
context.
- in the farther future, we could well start losing WebGL contexts of
tabs that have been inactive for a long time, as part of a more
general effort to reduce memory usage for users who have many
(sometimes: hundreds) of inactive tabs.

So, handling lost contexts will become increasingly important.

Benoit

2012/3/31 Lindsay Kay <lindsays...@gmail.com>:

Lindsay Kay

unread,
Mar 31, 2012, 3:02:29 PM3/31/12
to webgl-d...@googlegroups.com
Thanks Benoit,

that's really good to know. Understood - makes perfect sense to drop contexts to keep things responsive and also maybe to prevent DOS attacks via shaders.

Rehno Lindeque

unread,
Apr 1, 2012, 6:49:49 PM4/1/12
to webgl-d...@googlegroups.com
So I have a question, if a WebGL context is lost and restored, will its state persist? For example the following:

    gl.viewport(0, 0, canvas.width, canvas.height);
    gl.clearColor(0.0, 0.0, 0.0, 0.0);
    gl.cullFace(gl.BACK);
    gl.enable(gl.CULL_FACE);

...or do we need to explicitly restore all state?

Benoit Jacob

unread,
Apr 2, 2012, 12:11:34 PM4/2/12
to webgl-d...@googlegroups.com
You will need to explicitly restore all state.

Benoit

2012/4/1 Rehno Lindeque <rehno.l...@gmail.com>:

Rehno Lindeque

unread,
Apr 2, 2012, 3:04:45 PM4/2/12
to webgl-d...@googlegroups.com
Thanks Benoit, cheers


On Monday, April 2, 2012 9:11:34 AM UTC-7, bjacob wrote:
You will need to explicitly restore all state.

Benoit

2012/4/1 Rehno Lindeque:

Reply all
Reply to author
Forward
0 new messages