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

Re: [Public WebGL] Null return values from create*

On Fri, Mar 16, 2012 at 3:34 PM, Glenn Maynard <glenn@zewt.org> wrote:
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:

Actually, I think that is a very valid point and definitely eliminates a lot of the strange, racy behavior that would otherwise be horrid to consider in a confident manner.