Fixed bug 2122 - SDL_CreateTexture allows illegal texture sizes
authorSam Lantinga <slouken@libsdl.org>
Mon, 30 Sep 2013 22:16:14 -0700
changeset 777028031e0042b2
parent 7769 cf8dd3177612
child 7771 4434498bf4b9
Fixed bug 2122 - SDL_CreateTexture allows illegal texture sizes

Lloyd Bryant

SDL_CreateTexture() is succeeding (i.e. returning a valid pointer) when the requested horizontal or vertical size of the texture exceeds the maximum allowed by the render. This results in hard-to-understand errors showing up when later attempting to use that texture (such as with SDL_SetRenderTarget()).
src/render/SDL_render.c
src/render/opengles2/SDL_render_gles2.c
     1.1 --- a/src/render/SDL_render.c	Mon Sep 30 21:57:03 2013 -0700
     1.2 +++ b/src/render/SDL_render.c	Mon Sep 30 22:16:14 2013 -0700
     1.3 @@ -410,6 +410,11 @@
     1.4          SDL_SetError("Texture dimensions can't be 0");
     1.5          return NULL;
     1.6      }
     1.7 +    if ((renderer->info.max_texture_width && w > renderer->info.max_texture_width) ||
     1.8 +        (renderer->info.max_texture_height && h > renderer->info.max_texture_height)) {
     1.9 +        SDL_SetError("Texture dimensions are limited to %dx%d", renderer->info.max_texture_width, renderer->info.max_texture_height);
    1.10 +        return NULL;
    1.11 +    }
    1.12      texture = (SDL_Texture *) SDL_calloc(1, sizeof(*texture));
    1.13      if (!texture) {
    1.14          SDL_OutOfMemory();
     2.1 --- a/src/render/opengles2/SDL_render_gles2.c	Mon Sep 30 21:57:03 2013 -0700
     2.2 +++ b/src/render/opengles2/SDL_render_gles2.c	Mon Sep 30 22:16:14 2013 -0700
     2.3 @@ -1627,6 +1627,7 @@
     2.4  #endif
     2.5      Uint32 windowFlags;
     2.6      GLint window_framebuffer;
     2.7 +    GLint value;
     2.8  
     2.9      SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);
    2.10      SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
    2.11 @@ -1685,6 +1686,13 @@
    2.12          renderer->info.flags |= SDL_RENDERER_PRESENTVSYNC;
    2.13      }
    2.14  
    2.15 +    value = 0;
    2.16 +    rdata->glGetIntegerv(GL_MAX_TEXTURE_SIZE, &value);
    2.17 +    renderer->info.max_texture_width = value;
    2.18 +    value = 0;
    2.19 +    rdata->glGetIntegerv(GL_MAX_TEXTURE_SIZE, &value);
    2.20 +    renderer->info.max_texture_height = value;
    2.21 +
    2.22      /* Determine supported shader formats */
    2.23      /* HACK: glGetInteger is broken on the Zune HD's compositor, so we just hardcode this */
    2.24      rdata->glGetError();