Fixed BadMatch error in X11 renderer
authorSam Lantinga <slouken@libsdl.org>
Sat, 13 Dec 2008 13:10:53 +0000
changeset 2868 3b595278f813
parent 2867 eec7adc3d1c5
child 2869 2fe507a2ef7d
Fixed BadMatch error in X11 renderer
src/video/x11/SDL_x11render.c
--- 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;
         }