changeset 2868:3b595278f813

Fixed BadMatch error in X11 renderer
author Sam Lantinga <slouken@libsdl.org>
date Sat, 13 Dec 2008 13:10:53 +0000
parents eec7adc3d1c5
children 2fe507a2ef7d
files src/video/x11/SDL_x11render.c
diffstat 1 files changed, 13 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/video/x11/SDL_x11render.c	Sat Dec 13 12:34:28 2008 +0000
+++ b/src/video/x11/SDL_x11render.c	Sat Dec 13 13:10:53 2008 +0000
@@ -427,6 +427,15 @@
                          &attributes);
     depth = X11_GetDepthFromPixelFormat(data->format);
 
+    /* The image/pixmap depth must be the same as the window or you
+       get a BadMatch error when trying to putimage or copyarea.
+    */
+    if (depth != attributes.depth) {
+        X11_DestroyTexture(renderer, texture);
+        SDL_SetError("Texture format doesn't match window format");
+        return -1;
+    }
+
     if (data->yuv || texture->access == SDL_TEXTUREACCESS_STREAMING) {
 #ifndef NO_SHARED_MEMORY
         XShmSegmentInfo *shminfo = &data->shminfo;
@@ -475,6 +484,7 @@
         {
             data->pixels = SDL_malloc(texture->h * data->pitch);
             if (!data->pixels) {
+                X11_DestroyTexture(renderer, texture);
                 SDL_OutOfMemory();
                 return -1;
             }
@@ -485,6 +495,7 @@
                              SDL_BYTESPERPIXEL(data->format) * 8,
                              data->pitch);
             if (!data->image) {
+                X11_DestroyTexture(renderer, texture);
                 SDL_SetError("XCreateImage() failed");
                 return -1;
             }
@@ -494,6 +505,7 @@
             XCreatePixmap(renderdata->display, renderdata->window, texture->w,
                           texture->h, depth);
         if (data->pixmap == None) {
+            X11_DestroyTexture(renderer, texture);
             SDL_SetError("XCteatePixmap() failed");
             return -1;
         }
@@ -503,6 +515,7 @@
                          ZPixmap, 0, NULL, texture->w, texture->h,
                          SDL_BYTESPERPIXEL(data->format) * 8, data->pitch);
         if (!data->image) {
+            X11_DestroyTexture(renderer, texture);
             SDL_SetError("XCreateImage() failed");
             return -1;
         }