summaryrefslogtreecommitdiff
path: root/src/render
diff options
context:
space:
mode:
authorSylvain Becker <sylvain.becker@gmail.com>2021-01-27 10:20:13 +0100
committerSylvain Becker <sylvain.becker@gmail.com>2021-01-27 10:20:13 +0100
commit4951009f9dd8af946f99f298b4fa1dbf9cf580ee (patch)
tree7ccfdd29ba75350be1ec26aa866ee296ce6dabd2 /src/render
parent0eb034c87c04fe29fac814c663f6f7f400b86fed (diff)
downloadsdl-4951009f9dd8af946f99f298b4fa1dbf9cf580ee.tar.gz
SDL_UpdateTexture: intersect update rect with texture dimension
- fix crash with software renderer - fix non texture update with opengl/gles2
Diffstat (limited to 'src/render')
-rw-r--r--src/render/SDL_render.c25
1 files changed, 13 insertions, 12 deletions
diff --git a/src/render/SDL_render.c b/src/render/SDL_render.c
index 4102b7a61..139845f1e 100644
--- a/src/render/SDL_render.c
+++ b/src/render/SDL_render.c
@@ -1540,7 +1540,7 @@ int
SDL_UpdateTexture(SDL_Texture * texture, const SDL_Rect * rect,
const void *pixels, int pitch)
{
- SDL_Rect full_rect;
+ SDL_Rect real_rect;
CHECK_TEXTURE_MAGIC(texture, -1);
@@ -1551,28 +1551,30 @@ SDL_UpdateTexture(SDL_Texture * texture, const SDL_Rect * rect,
return SDL_InvalidParamError("pitch");
}
- if (!rect) {
- full_rect.x = 0;
- full_rect.y = 0;
- full_rect.w = texture->w;
- full_rect.h = texture->h;
- rect = &full_rect;
+ real_rect.x = 0;
+ real_rect.y = 0;
+ real_rect.w = texture->w;
+ real_rect.h = texture->h;
+ if (rect) {
+ if (!SDL_IntersectRect(rect, &real_rect, &real_rect)) {
+ return 0;
+ }
}
- if ((rect->w == 0) || (rect->h == 0)) {
+ if (real_rect.w == 0 || real_rect.h == 0) {
return 0; /* nothing to do. */
#if SDL_HAVE_YUV
} else if (texture->yuv) {
- return SDL_UpdateTextureYUV(texture, rect, pixels, pitch);
+ return SDL_UpdateTextureYUV(texture, &real_rect, pixels, pitch);
#endif
} else if (texture->native) {
- return SDL_UpdateTextureNative(texture, rect, pixels, pitch);
+ return SDL_UpdateTextureNative(texture, &real_rect, pixels, pitch);
} else {
SDL_Renderer *renderer = texture->renderer;
if (FlushRenderCommandsIfTextureNeeded(texture) < 0) {
return -1;
}
- return renderer->UpdateTexture(renderer, texture, rect, pixels, pitch);
+ return renderer->UpdateTexture(renderer, texture, &real_rect, pixels, pitch);
}
}
@@ -1890,7 +1892,6 @@ SDL_LockTextureToSurface(SDL_Texture *texture, const SDL_Rect *rect,
real_rect.y = 0;
real_rect.w = texture->w;
real_rect.h = texture->h;
-
if (rect) {
SDL_IntersectRect(rect, &real_rect, &real_rect);
}