[Public WebGL] Return value for getAttachedShaders when a null program is passed in

Glenn Maynard [email protected]
Sun Apr 15 20:58:12 PDT 2012

On Sun, Apr 15, 2012 at 10:16 PM, Boris Zbarsky <[email protected]> wrote:

> The spec doesn't seem to define what should happen when a null program is
> passed to getAttachedShaders.  The OpenGL ES spec doesn't define behavior
> here, since it uses an integer to identify the program, and that can't be
> null.

There's probably an ES spec bug there.  However, the return value of
functions that fail with an error isn't defined by OpenGL.  That's because
it never (as far as I know) actually has return values, and always returns
values into output parameters:

void glGetAttachedShaders(uint program, sizei maxCount, sizei *count, uint

That sidesteps the question of what to return.  It simply doesn't modify
the parameter, so the pattern in C becomes:

int count = 0;
int shaders[1024];
glGetAttachedShaders(program, 1024, &count, shaders);

In other words, the caller defines the return value, not OpenGL.  The
result in WebGL is an ordinary return value, so the above no longer applies
and WebGL does need to explicitly define the return value.

This applies not only for null, but also if the program has been deleted,
or if it's been invalidated due to a lost context.  (Currently, the lost
context case is defined by 5.14 as returning null, but the null and deleted
object cases aren't.)

Per current IDL, the return values that could possibly make sense are null
> and empty array.  Gecko seems to return undefined or some such, based on
> code inspection, which is clearly wrong, but I don't know which direction
> to fix it in.

I'd recommend returning an empty array, and generating INVALID_OPERATION.
That way, this always works:

var shaders = ctx.getAttachedShaders(program);
for(var i = 0; i < shaders.length; ++i) ...

rather than failing obscurely on context loss.  That would make the return
value non-nullable, and add explicit context lost handling (so it can be
applied to the context lost case too, as well as deleted and null objects).

Glenn Maynard
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://khronos.org/pipermail/public_webgl_khronos.org/attachments/20120415/4292a212/attachment.html>

More information about the public_webgl mailing list