KhronosGroup/WebGL

Clarification regarding context loss handling

Opened this issue · 2 comments

Khronos' documentation on handling context loss states:

Don’t check for null on creation
var program = gl.createProgram();
if (program === null) // BAD!!!
You should really only get null from these functions if the context is lost and in that case there’s no reason to check. WebGL is designed so that for the most part everything just runs as normal even when a program or shader is null.

However, it's recently come to my attention that implementations will raise errors if you apply the "keep on truckin'" approach recommended in the above documentation:

microsoft/TypeScript-DOM-lib-generator#1262 (comment)

Is the documentation incorrect, or are the implementations incorrect?

Actually it sounds like yes, stuff broke. Browsers started validating the arguments after WebGL shipped. So, you'd need to check every return value and not use them if they are null :(

So, I think this is arguably a bug or should at least be discussed. It looks like an oversight in the conformance tests. The test

sdk/tests/conformance/context/context-lost.html

Seems like it should have tested for that? It's seem pretty clear to me the design was supposed to be that context lost is safe to call everything and the test above certainly tests that running with previously valid objects continues to work. It's also arguably clear of OpenGL itself?

Functions that would fail of the top of my head would be

attachShader
compileShader
detachShader
getActiveAttrib
getActiveUniform
getAttachedShaders
getAttribLocation
getBufferParameter
getProgramInfoLog
getProgramParameter
getShaderInfoLog
getShaderParameter
getShaderSource
getUniform
getUniformLocation
getFragDataLocation
beginQuery
getQueryParameter
clientWaitSync
waitSync
getSyncParameter
transformFeedbackVaryings
getTransformFeedbackVarying
getUniformIndices
getActiveUniforms
getActiveUniformBlockParameter
getActiveUniformBlockName
uniformBlockBinding