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

[Public WebGL] Null return values on context loss



When the context is lost, "methods returning nullable values or any return null". This seems very hard to deal with correctly, since you have to deal with a very rare return value. For example,

return ctx.getVertexAttrib(idx, ctx.CURRENT_VERTEX_ATTRIB)[0];

will fail if the context is lost, since attr will be null. This requires C-style per-call error handling, which makes it hard (and tedious) to write correct code.

It seems like the expectation was that null returns would work implicitly, without the caller needing to check for null. That mostly works for things like WebGLTexture, which has no methods and is only passed to functions which accept null. However, it doesn't seem like this holds consistently throughout all affected API calls.

I'm not sure what the right thing to do would be, though. Throwing an exception would be an improvement, at least.

Also, the above says "nullable values". I assume that "nullable types" was intended, eg. http://dev.w3.org/2006/webapi/WebIDL/#idl-nullable-type, but as far as I can find, there are no nullable types (eg. "DOMString?") in WebGL's IDL. Based on what's actually happening here (most functions can't return anything meaningful when the context is lost), I'm guessing it was intended that *all* (or almost all) non-null return values in WebGL be nullable?

--
Glenn Maynard