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

[Public WebGL] Null return values from create*



On Fri, Mar 16, 2012 at 12:58 PM, Gregg Tavares (å) <gman@google.com> wrote:
All the ones below here NEED to continue to allow NULL otherwise they will start throwing exceptions on context lost when all the createXXX functions start returning NULL.

I think that's a bit of a design error. If you call eg. createTexture while the context is lost, it should probably return a WebGLTexture with the invalidated flag already set, instead of returning null.

This has a few benefits. First, it eliminates the above problem; functions don't need to be nullable when it's not the natural thing to do.

Second, it reduces the number of failure cases. Currently, if you do the following, two different things might happen on context loss:

tex = ctx.createTexture();
ctx.bindTexture(ctx.TEXTURE_2D, tex);

If the context was lost before createTexture is called, tex is null. However, the context might be lost *between* the createTexture and bindTexture calls. If that happens, bindTexture receives a non-null texture whose invalidated flag is set. These cases would be merged, so there's only one error path to worry about.

Third, that things like this don't break in subtle, racy ways, because tex is never null:

tex = ctx.createTexture();
tex.sourceImageUrl = url; // remember where this came from

That reduces the number of ways asynchronous context loss can cause bugs. That's a big win, since the asynchronous nature of context loss is very alien to the platform.

This would also be an almost entirely backwards-compatible change, since the null return value case is simply merged into the lost-immediately-after-return case that already exists.

--
Glenn Maynard