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

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



On Wed, Apr 4, 2012 at 4:20 PM, Boris Zbarsky <bzbarsky@mit.edu> 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.

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.

--
Glenn Maynard