W3C home > Mailing lists > Public > whatwg@whatwg.org > April 2011

[whatwg] Canvas.getContext error handling

From: Glenn Maynard <glenn@zewt.org>
Date: Wed, 13 Apr 2011 19:43:46 -0400
Message-ID: <BANLkTimmgyDUMX0eXqdTf47EHs+LZ66TWA@mail.gmail.com>
On Wed, Apr 13, 2011 at 4:21 PM, Kenneth Russell <kbr at google.com> wrote:

> It's essential to be able to report more detail about why context
> creation failed. We have already received a lot of feedback from users
> and developers of popular projects like Google Body that doing so will
> reduce end user frustration and provide them a path toward getting the
> content to work.
>

Hixie says this is a bad idea, for security reasons, and that the UA should
just tell the user directly:
http://krijnhoetmer.nl/irc-logs/whatwg/20110413#l-1056

That said, the discussion lead to another approach:

Calling canvas.getContext("webgl", {async: true}) will cause it to *always*
return an object immediately, without attempting to initialize the
underlying drawing context.  This context starts out in the "lost" state.
As long as WebGL is supported by the browser, getContext will never return
null, even for blacklisted GPUs.  The context is initialized
asynchronously.  On success, webglcontextrestored is fired, as if the
context had just come back from a normal context loss.  On failure,
webglcontextcreationerror is fired with a statusMessage, and possibly a flag
indicating whether it's a permanent failure (GPU blacklisted) or a
recoverable one (insufficient resources).

If {async: true} isn't specified, then an initial context failure returns
null (using the "unsupported contextId" approach), and there's no interface
to get an error message--people should be strongly discouraged from using
this API (deprecating it if possible).

(If it's possible to make the backwards-incompatible change to remove sync
initialization entirely, that would be good to do, but I'm assuming it's
not.)

There are other fine details (such as feature detection, and possibly
distinguishing "initializing" from "lost"), but I'll wait for people to give
their thoughts before delving in deeper.  Aside from giving a consistent way
to report errors, this allows browsers to initialize WebGL contexts in the
background.

-- 
Glenn Maynard
Received on Wednesday, 13 April 2011 16:43:46 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Wednesday, 30 January 2013 18:48:03 GMT