From 5315089abe9321819efaa4f08169108b2172bd89 Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Sun, 20 Feb 2011 12:02:48 +0000 Subject: [PATCH] Fix numerous resource leaks in scene.cpp. --- src/scene.cpp | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/src/scene.cpp b/src/scene.cpp index a9775fcb..450a0d03 100644 --- a/src/scene.cpp +++ b/src/scene.cpp @@ -89,6 +89,7 @@ Scene::~Scene() /* FIXME: this must be done while the GL context is still active. * Change the architecture to make sure of that. */ glDeleteBuffers(data->nbufs, data->bufs); + free(data->bufs); delete data; } @@ -199,38 +200,39 @@ void Scene::Render() // XXX: rename to Blit() } #if LOL_EXPERIMENTAL - GLuint vao, vbo[2], attr; + GLuint vao; glGenVertexArrays(1, &vao); glBindVertexArray(vao); - glGenBuffers(2, &vbo[0]); - - glBindBuffer(GL_ARRAY_BUFFER, vbo[0]); - glBufferData(GL_ARRAY_BUFFER, 18 * (n - i) * sizeof(GLfloat), vertex, GL_STATIC_DRAW); - glVertexAttribPointer(attr_pos, 3, GL_FLOAT, GL_FALSE, 0, 0); - glEnableVertexAttribArray(attr_pos); - - glBindBuffer(GL_ARRAY_BUFFER, vbo[1]); - glBufferData(GL_ARRAY_BUFFER, 12 * (n - i) * sizeof(GLfloat), texture, GL_STATIC_DRAW); - glVertexAttribPointer(attr_tex, 2, GL_FLOAT, GL_FALSE, 0, 0); - glEnableVertexAttribArray(attr_tex); - - stdshader->Bind(); #else glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_TEXTURE_COORD_ARRAY); +#endif glBindBuffer(GL_ARRAY_BUFFER, data->bufs[buf]); - glBufferData(GL_ARRAY_BUFFER, 6 * 3 * (n - i) * sizeof(float), - vertex, GL_DYNAMIC_DRAW); + glBufferData(GL_ARRAY_BUFFER, 18 * (n - i) * sizeof(GLfloat), + vertex, GL_STATIC_DRAW); +#if LOL_EXPERIMENTAL + glVertexAttribPointer(attr_pos, 3, GL_FLOAT, GL_FALSE, 0, 0); + glEnableVertexAttribArray(attr_pos); +#else glVertexPointer(3, GL_FLOAT, 0, NULL); +#endif glBindBuffer(GL_ARRAY_BUFFER, data->bufs[buf + 1]); - glBufferData(GL_ARRAY_BUFFER, 6 * 2 * (n - i) * sizeof(float), - texture, GL_DYNAMIC_DRAW); + glBufferData(GL_ARRAY_BUFFER, 12 * (n - i) * sizeof(GLfloat), + texture, GL_STATIC_DRAW); +#if LOL_EXPERIMENTAL + glVertexAttribPointer(attr_tex, 2, GL_FLOAT, GL_FALSE, 0, 0); + glEnableVertexAttribArray(attr_tex); +#else glTexCoordPointer(2, GL_FLOAT, 0, NULL); #endif +#if LOL_EXPERIMENTAL + stdshader->Bind(); +#endif + Tiler::Bind(data->tiles[i].code); glDrawArrays(GL_TRIANGLES, 0, (n - i) * 6);