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()).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
diff --git a/src/render/SDL_render.c b/src/render/SDL_render.c
index 8420d2f..5546d4a 100644
--- a/src/render/SDL_render.c
+++ b/src/render/SDL_render.c
@@ -410,6 +410,11 @@ SDL_CreateTexture(SDL_Renderer * renderer, Uint32 format, int access, int w, int
SDL_SetError("Texture dimensions can't be 0");
return NULL;
}
+ if ((renderer->info.max_texture_width && w > renderer->info.max_texture_width) ||
+ (renderer->info.max_texture_height && h > renderer->info.max_texture_height)) {
+ SDL_SetError("Texture dimensions are limited to %dx%d", renderer->info.max_texture_width, renderer->info.max_texture_height);
+ return NULL;
+ }
texture = (SDL_Texture *) SDL_calloc(1, sizeof(*texture));
if (!texture) {
SDL_OutOfMemory();
diff --git a/src/render/opengles2/SDL_render_gles2.c b/src/render/opengles2/SDL_render_gles2.c
index 484186e..10cb42d 100644
--- a/src/render/opengles2/SDL_render_gles2.c
+++ b/src/render/opengles2/SDL_render_gles2.c
@@ -1627,6 +1627,7 @@ GLES2_CreateRenderer(SDL_Window *window, Uint32 flags)
#endif
Uint32 windowFlags;
GLint window_framebuffer;
+ GLint value;
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
@@ -1685,6 +1686,13 @@ GLES2_CreateRenderer(SDL_Window *window, Uint32 flags)
renderer->info.flags |= SDL_RENDERER_PRESENTVSYNC;
}
+ value = 0;
+ rdata->glGetIntegerv(GL_MAX_TEXTURE_SIZE, &value);
+ renderer->info.max_texture_width = value;
+ value = 0;
+ rdata->glGetIntegerv(GL_MAX_TEXTURE_SIZE, &value);
+ renderer->info.max_texture_height = value;
+
/* Determine supported shader formats */
/* HACK: glGetInteger is broken on the Zune HD's compositor, so we just hardcode this */
rdata->glGetError();