[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 1:39 PM, Patrick Baggett
<baggett.patrick@gmail.com> wrote:
>
>
> 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.

Glenn, thanks for raising this issue again. After giving this more
thought I am increasingly in favor of your proposal to return
invalidated WebGLObjects from the create* methods if the context is
lost, because of the unification of error handling behavior.

There are some things to consider. It will still be the case that some
get* methods will return null values in certain situations, in
particular when passed invalidated objects (per
http://www.khronos.org/registry/webgl/specs/latest/#5.14). Is this an
issue? If the goal is to eliminate the majority of null return values
under error conditions, that is a much larger change, and one which I
think should be done incrementally.

What are others' opinions on this potential change?

It would allow the spec to be tightened up in several places, as
nullable arguments could be changed to non-nullable. I don't think the
two changes (to the create* methods' semantics and to various methods'
nullable arguments) would have a significant compatibility impact on
existing WebGL content. Generally, the only reason that null arguments
would float in to these methods would be because of a context lost
event. Instead, invalidated objects would float in, leading to
INVALID_OPERATION errors. The TypeErrors that would be thrown because
of incoming null values would not occur.

The conformance tests would have to be updated, and previous versions
of the conformance suite would be broken, since there are some tests
that explicitly pass in null, and these would begin to throw
exceptions. However, I don't think real-world content would be broken.

-Ken

-----------------------------------------------------------
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
-----------------------------------------------------------