Skip to content

Instantly share code, notes, and snippets.

@rygorous
Created October 26, 2012 18:07
Embed
What would you like to do?
// The native handle type holds resource handles and a coarse description.
typedef union {
// handle that is a texture
struct {
GLuint gl;
GLuint gl_renderbuf;
} tex;
// handle that is a vertex buffer
struct {
GLuint base;
GLuint indices;
} vbuf;
} GDrawNativeHandle;
// ...
static void eat_gl_err(void)
{
while (glGetError() != GL_NO_ERROR);
}
static void opengl_check(void)
{
GLint e = glGetError();
if (e != GL_NO_ERROR) {
report_err(e); // prints a message and exits in my test
eat_gl_err();
}
}
// ...
static void api_free_resource(GDrawHandle *r)
{
if (!r->cache->is_vertex) { // <- is_vertex was not set for VBOs here
// so VBOs went through here...
glDeleteTextures(1, &r->handle.tex.gl);
if (r->handle.tex.gl_renderbuf && r->handle.tex.gl_renderbuf != r->handle.tex.gl)
glDeleteRenderbuffers(1, &r->handle.tex.gl_renderbuf);
} else {
// ...instead of through here, generating glDeleteTextures/glRenderbuffers for then-unassigned names.
glDeleteBuffers(1, &r->handle.vbuf.base);
glDeleteBuffers(1, &r->handle.vbuf.indices);
}
opengl_check(); // <- no error reported here, driver crashes in second thread a while later.
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment