Reputation: 5557
What exactly is the behavior of glGenBuffers (or any GL gen function) if for some reason it fails to create a buffer? Will the buffers be set to zero by the function to indicate failure? If this is the case, the documentation makes no mention of it. Basically I'm asking if this is safe:
GLuint buffer; //uninitialized variable
glGenBuffers(1, &buffer);
if(buffer)
{
...
}
If glGenBuffers doesn't set buffer to zero in the case of a failure then buffer will remain uninitialized and result in undefined behavior.
Upvotes: 0
Views: 1779
Reputation: 4482
The OpenGL reference manual doesn't say anything about NULLing buffers for glGenBuffers in case of errors. So relying on it would be a baaad idea.
Instead it says that GL_INVALID_VALUE may be generated. You can check for that error by using if (glGetError() == GL_NO_ERROR) instead of checking your buffer.
Although I strongly advise to check error codes all the time, in this particular case it might be overkill. It seems to me that glGenBuffers will never fail if you use it to initialize a single buffer, because n
is guaranteed to be positive (n=1). So glGenBuffers will either succeed or crash horribly. So no need to check for errors in any case.
Upvotes: 3