[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Public WebGL] Null return values from create*
On Thu, Apr 5, 2012 at 5:33 PM, Glenn Maynard <email@example.com>
On Thu, Apr 5, 2012 at 7:11 PM, Gregg Tavares (勤) <firstname.lastname@example.org>
Wait what? How would exceptions help here? Is it even possible to use exceptions AND get performance AND get no surprises during context lost?
There are no performance issues with using exceptions for synchronous errors like these. The usual problem with exceptions is for *asynchronous* errors--ones that can't be detected before the function returns without forcing a glFinish(), and can only be checked with getError. That is, having stencilFunc throw an exception would cause a performance problem, because you'd have to wait for the action that the function queues to complete before returning. For functions like getParameter and getProgramInfoLog, you already have to wait for it to finish in order to know what to return.
With exceptions, the rare context-lost error cases are a lot easier for users to handle reliably. Problems can still crop up--you still have to test your exception handling--but it's a huge improvement over C-style return-value error handling.
It's probably much too late for anything like this, since it'd be a breaking change. (I suppose it could be an extension, that when loaded, changes dispatch step 6.2 from "return null" to "throw an exception". I'd be sort of afraid of an extension like that segmenting WebGL libraries into two groups, though--ones that only work with the extension and ones that only work without it.)
I'm still not sure what you are suggesting. That calling any function during context lost throws an exception? that sounds far more surprising to me than returning NULL.
The whole point of returning and accepting NULL is that with a few simple rules you have do nothing special during context lost. All the code will just keep running but doing nothing. If every create threw an exception now you'd have to have all kinds of special cases to handle every place you call createXXX. I don't see how that's a win.