Fix #29615: Crash during undo after toggling "Float buffer" in image paint mode

Crash was caused by different types of buffers stored in tile in undo stack and in
image itself. Store type of buffer in tile, so byte tile wouldn't be applying on
float image anymore.
This commit is contained in:
Sergey Sharybin 2011-12-15 08:01:49 +00:00
parent 9e4d9e066a
commit ca9ae04220

@ -383,7 +383,7 @@ typedef struct UndoImageTile {
void *rect;
int x, y;
short source;
short source, use_float;
char gen_type;
} UndoImageTile;
@ -413,11 +413,13 @@ static void *image_undo_push_tile(Image *ima, ImBuf *ibuf, ImBuf **tmpibuf, int
ListBase *lb= undo_paint_push_get_list(UNDO_PAINT_IMAGE);
UndoImageTile *tile;
int allocsize;
short use_float = ibuf->rect_float ? 1 : 0;
for(tile=lb->first; tile; tile=tile->next)
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(tile->use_float == use_float)
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);
@ -435,6 +437,7 @@ static void *image_undo_push_tile(Image *ima, ImBuf *ibuf, ImBuf **tmpibuf, int
tile->gen_type= ima->gen_type;
tile->source= ima->source;
tile->use_float= use_float;
undo_copy_tile(tile, *tmpibuf, ibuf, 0);
undo_paint_push_count_alloc(UNDO_PAINT_IMAGE, allocsize);
@ -455,6 +458,8 @@ static void image_undo_restore(bContext *C, ListBase *lb)
IB_rectfloat|IB_rect);
for(tile=lb->first; tile; tile=tile->next) {
short use_float;
/* find image based on name, pointer becomes invalid with global undo */
if(ima && strcmp(tile->idname, ima->id.name)==0) {
/* ima is valid */
@ -464,6 +469,7 @@ static void image_undo_restore(bContext *C, ListBase *lb)
}
ibuf= BKE_image_get_ibuf(ima, NULL);
use_float = ibuf->rect_float ? 1 : 0;
if(ima && ibuf && strcmp(tile->ibufname, ibuf->name)!=0) {
/* current ImBuf filename was changed, probably current frame
@ -480,6 +486,9 @@ static void image_undo_restore(bContext *C, ListBase *lb)
if (ima->gen_type != tile->gen_type || ima->source != tile->source)
continue;
if (use_float != tile->use_float)
continue;
undo_copy_tile(tile, tmpibuf, ibuf, 1);
GPU_free_image(ima); /* force OpenGL reload */