Check the return value of glGenTextures()
authorSam Lantinga <slouken@libsdl.org>
Sat, 10 Aug 2013 10:49:26 -0700
changeset 7624 ac9f3b12c42a
parent 7623 fe1b8a78de0b
child 7626 36e493277423
Check the return value of glGenTextures()
src/render/opengl/SDL_render_gl.c
src/render/opengles/SDL_render_gles.c
src/render/opengles2/SDL_render_gles2.c
--- a/src/render/opengl/SDL_render_gl.c	Sat Aug 10 13:46:19 2013 -0400
+++ b/src/render/opengl/SDL_render_gl.c	Sat Aug 10 10:49:26 2013 -0700
@@ -633,6 +633,10 @@
 
     GL_CheckError("", renderer);
     renderdata->glGenTextures(1, &data->texture);
+    if (GL_CheckError("glGenTexures()", renderer) < 0) {
+        SDL_free(data);
+        return -1;
+    }
     if ((renderdata->GL_ARB_texture_rectangle_supported)
         /*&& texture->access != SDL_TEXTUREACCESS_TARGET*/){
         data->type = GL_TEXTURE_RECTANGLE_ARB;
--- a/src/render/opengles/SDL_render_gles.c	Sat Aug 10 13:46:19 2013 -0400
+++ b/src/render/opengles/SDL_render_gles.c	Sat Aug 10 10:49:26 2013 -0700
@@ -475,6 +475,11 @@
     renderdata->glGetError();
     renderdata->glEnable(GL_TEXTURE_2D);
     renderdata->glGenTextures(1, &data->texture);
+    result = renderdata->glGetError();
+    if (result != GL_NO_ERROR) {
+        SDL_free(data);
+        return GLES_SetError("glGenTextures()", result);
+    }
 
     data->type = GL_TEXTURE_2D;
     /* no NPOV textures allowed in OpenGL ES (yet) */
--- a/src/render/opengles2/SDL_render_gles2.c	Sat Aug 10 13:46:19 2013 -0400
+++ b/src/render/opengles2/SDL_render_gles2.c	Sat Aug 10 10:49:26 2013 -0700
@@ -418,6 +418,10 @@
     /* Allocate the texture */
     rdata->glGetError();
     rdata->glGenTextures(1, &tdata->texture);
+    if (rdata->glGetError() != GL_NO_ERROR) {
+        SDL_free(tdata);
+        return SDL_SetError("Texture creation failed in glGenTextures()");
+    }
     rdata->glActiveTexture(GL_TEXTURE0);
     rdata->glBindTexture(tdata->texture_type, tdata->texture);
     rdata->glTexParameteri(tdata->texture_type, GL_TEXTURE_MIN_FILTER, scaleMode);
@@ -425,8 +429,7 @@
     rdata->glTexParameteri(tdata->texture_type, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
     rdata->glTexParameteri(tdata->texture_type, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
     rdata->glTexImage2D(tdata->texture_type, 0, format, texture->w, texture->h, 0, format, type, NULL);
-    if (rdata->glGetError() != GL_NO_ERROR)
-    {
+    if (rdata->glGetError() != GL_NO_ERROR) {
         rdata->glDeleteTextures(1, &tdata->texture);
         SDL_free(tdata);
         return SDL_SetError("Texture creation failed");