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

[whatwg] Canvas.getContext error handling

From: Glenn Maynard <glenn@zewt.org>
Date: Sat, 9 Apr 2011 22:55:24 -0400
Message-ID: <BANLkTimo3JXAjxHPMNW-Az6-A47LjP6gNw@mail.gmail.com>
getContext doesn't specify error handling.  WebGL solves this oddly: if an
error occurs, it dispatches an event with error details at the canvas.  It's
odd for a synchronous API to report error information with an event; it
would make a lot more sense to raise an exception.  However, getContext
doesn't specify error handling for the "Return a new object for contextId"
algorithms.

The "primary context" should only be set by getContext after "Return a new
object for contextId" completes successfully; it shouldn't be set on error.
The cached return value used in step 5 should also only happen after
success; don't cache a null response.  This way, you can retry getContext on
failure, and getContext is a straightforward no-op after an error.

(I don't know if the WebGL folks could be convinced to change to throwing an
exception or if they want to continue returning null and firing an event.)

Related thread:
https://www.khronos.org/webgl/public-mailing-list/archives/1104/msg00027.html

-- 
Glenn Maynard
Received on Saturday, 9 April 2011 19:55:24 GMT

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