[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Public WebGL] getContext error handling



Hey Glenn,

We discussed this in the thread "Firefox 4 and blacklist reporting".
Indeed the current paragraph on webglcontextcreationerror is just
plain confusing and not describing what's happening in reality from a
JavaScript developer perspective.

I proposed to replace the paragraph with :
"
This event is dispatched from the HTMLCanvasElement by getContext()
when an error occurs during that call.
The event allows to collect details about the failure that will result
in getContext() returning null.
"

Makes it much clearer imo, consistent with how it should be/is usually
implemented, and compatible with the snippet of code you posted that
gives details about the error (I posted another similar snippet in the
thread aforementioned).

If there's no objection, I'll replace the paragraph with proposal
above in the spec.


Regards,


On Sat, Apr 9, 2011 at 10:38, Glenn Maynard <glenn@zewt.org> wrote:
> The error handling for canvas.getContext("webgl") is inconsistent with other
> web APIs. Synchronous APIs, like FileReaderSync and IDBDatabaseSync, report
> errors by throwing exceptions with error information. Asynchronous APIs,
> like FileReader and IDBDatabase, report errors by firing an event.
> getContext is a synchronous API, but WebGL is reporting errors using the
> event mechanism used by asynchronous APIs. It should be throwing an
> exception instead.
>
> A related issue: the description of webglcontextcreationerror is vague. It
> says "Later, at the normal event delivery time". Events can be dispatched
> either in the event loop (async exceptions) or immediately (sync
> exceptions); there's no such thing as the "normal event delivery time". It
> sounds like this was written under the assumption that all events are
> asynchronous. HTML's terminology for this is concise and precise: "fire a
> simple event" to fire an event immediately, and "queue a task to fire a
> simple event" to fire an event later from the event loop.
>
> If it's too late to replace webglcontextcreationerror with an exception,
> note that this event should be fired synchronously, not asynchronously, so
> it's possible to retrieve error information as a result of a getContext call
> immediately. For example:
>
> ÂÂÂ var error = "";
> ÂÂÂ var retrieveError = function(e) {Â error = e.statusMessage || "unknown
> error"; };
> ÂÂÂ canvas.addEventListener("webglcontextcreationerror", retrieveError,
> false);
> ÂÂÂ var ctx = canvas.getContext("experimental-webgl");
> ÂÂÂ canvas.removeEventListener("webglcontextcreationerror", retrieveError,
> false);
> ÂÂÂ if(!ctx)
> ÂÂÂ ÂÂÂ alert("WebGL error: " + error);
>
> Note that this event is already synchronous in Chrome, so the above code
> already works there.
>
> --
> Glenn Maynard
>
>

-----------------------------------------------------------
You are currently subscribed to public_webgl@khronos.org.
To unsubscribe, send an email to majordomo@khronos.org with
the following command in the body of your email:
unsubscribe public_webgl
-----------------------------------------------------------