Fix #27532: Undo test texture after painting gives black blocks.
authorSergey Sharybin <sergey.vfx@gmail.com>
Mon, 3 Oct 2011 13:01:24 +0000 (13:01 +0000)
committerSergey Sharybin <sergey.vfx@gmail.com>
Mon, 3 Oct 2011 13:01:24 +0000 (13:01 +0000)
- Do not apply undo tiles on image if source or generated type was changed.
- Added null-check in own recent commit in this area.

source/blender/editors/sculpt_paint/paint_image.c

index d556ff9797f60f9720142caf8298a00129c4d952..36711d14bebe08c60befcf8c4819a5ceb3a888fd 100644 (file)
@@ -360,6 +360,9 @@ typedef struct UndoImageTile {
 
        void *rect;
        int x, y;
+
+       short source;
+       char gen_type;
 } UndoImageTile;
 
 static ImagePaintPartialRedraw imapaintpartial = {0, 0, 0, 0, 0};
@@ -390,8 +393,9 @@ static void *image_undo_push_tile(Image *ima, ImBuf *ibuf, ImBuf **tmpibuf, int
        int allocsize;
 
        for(tile=lb->first; tile; tile=tile->next)
-               if(tile->x == x_tile && tile->y == y_tile && strcmp(tile->idname, ima->id.name)==0 && strcmp(tile->ibufname, ibuf->name)==0)
-                       return tile->rect;
+               if(tile->x == x_tile && tile->y == y_tile && ima->gen_type == tile->gen_type && ima->source == tile->source)
+                       if(strcmp(tile->idname, ima->id.name)==0 && strcmp(tile->ibufname, ibuf->name)==0)
+                               return tile->rect;
        
        if (*tmpibuf==NULL)
                *tmpibuf = IMB_allocImBuf(IMAPAINT_TILE_SIZE, IMAPAINT_TILE_SIZE, 32, IB_rectfloat|IB_rect);
@@ -407,6 +411,9 @@ static void *image_undo_push_tile(Image *ima, ImBuf *ibuf, ImBuf **tmpibuf, int
 
        strcpy(tile->ibufname, ibuf->name);
 
+       tile->gen_type= ima->gen_type;
+       tile->source= ima->source;
+
        undo_copy_tile(tile, *tmpibuf, ibuf, 0);
        undo_paint_push_count_alloc(UNDO_PAINT_IMAGE, allocsize);
 
@@ -436,7 +443,7 @@ static void image_undo_restore(bContext *C, ListBase *lb)
 
                ibuf= BKE_image_get_ibuf(ima, NULL);
 
-               if(ima && strcmp(tile->ibufname, ibuf->name)!=0) {
+               if(ima && ibuf && strcmp(tile->ibufname, ibuf->name)!=0) {
                        /* current ImBuf filename was changed, probably current frame
                           was changed when paiting on image sequence, rather than storing
                           full image user (which isn't so obvious, btw) try to find ImBuf with
@@ -448,6 +455,9 @@ static void image_undo_restore(bContext *C, ListBase *lb)
                if (!ima || !ibuf || !(ibuf->rect || ibuf->rect_float))
                        continue;
 
+               if (ima->gen_type != tile->gen_type || ima->source != tile->source)
+                       continue;
+
                undo_copy_tile(tile, tmpibuf, ibuf, 1);
 
                GPU_free_image(ima); /* force OpenGL reload */