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

Re: [Public WebGL] Null return values on context loss

On Sat, Nov 12, 2011 at 11:22 PM, Glenn Maynard <glenn@zewt.org> wrote:
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.

Correct. Yet except for debugging apps there is generally no reason to call ctx.getVertexAttrib.  Of course that doesn't mean we shouldn't fix this problem.

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.

It works for WebGLTexture unless you do this

tex = gl.createTexture();
tex.url = "">

I had to fix code that did that when I made the code handle lost context.


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

No that would be just as a bad if not worse.

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?

Ideally, each function would return something that is unlikely to break code. We can either change the spec or add some examples (or a link to examples) showing the correct usages. Something like this


with more examples added for getVertexAttrib etc.

Glenn Maynard