[Public WebGL] What should getContextAttributes return after the context has been lost?

Kenneth Russell [email protected]
Wed Apr 4 16:43:48 PDT 2012

On Wed, Apr 4, 2012 at 3:39 PM, Glenn Maynard <[email protected]> wrote:
> On Wed, Apr 4, 2012 at 4:20 PM, Boris Zbarsky <[email protected]> wrote:
>> The IDL says:
>>  WebGLContextAttributes getContextAttributes();
>> This is not a method that has explicit context lost handling, so we end up
>> in the 6-step algorithm in
>> https://www.khronos.org/registry/webgl/specs/latest/#5.14
>> We reach step 5 with "use default value" set to true.
>> We return nothing in step 5.1, since the return value is not a nullable
>> type or 'any'.
>> Step 5.2 says "Terminate this algorithm without calling the method
>> implementation".  What does that mean?  What's the actual return value?  Is
>> a JS exception thrown?  If so, which one?
>> I'm guessing the return type in this case should just be
>> "WebGLContextAttributes?"...
> Since it's easy to keep this information around after a context loss, I
> think it'd be better for this function to have explicit context lost
> handling, and always return the context attributes.  Not returning null when
> we don't have to eliminates the user bugs that will be caused by rarely
> returning null.  People don't write:
> var attr = ctx.getContextAttributes()
> if(attr != null && attr.alpha)
>     // ...
> they simply say "if(ctx.getContextAttributes().alpha)".  Never returning
> null eliminates an entire small category of bugs.

Agreed, getContextAttributes should never return null. Added explicit
context lost handling for this method and documented what it does.
Please post if you see any issues with this edit.

> There may be other uses of being able to grab the context attributes after a
> context loss, too, eg. someCanvas.getContext("webgl",
> otherCtx.getContextAttributes()).
>> There are similar issues with various creation functions and whatnot.
> For functions like createTexture, I think they should behave as described in
> https://www.khronos.org/webgl/public-mailing-list/archives/1203/msg00086.html.
> If that's done, those functions would have explicit context loss handling,
> and wouldn't have nullable return values.

I agree with this more the more I think about it. Will reply to the
other thread.


You are currently subscribed to [email protected]
To unsubscribe, send an email to [email protected] with
the following command in the body of your email:
unsubscribe public_webgl

More information about the public_webgl mailing list