[Bf-blender-cvs] [6e72797] soc-2013-paint: Fix undo after paint curve editing crashing on sculpt mode. Also fix bad file write of paint curves.

Antony Riakiotakis noreply at git.blender.org
Tue Jun 10 16:29:31 CEST 2014


Commit: 6e7279752af01069cf7e6062bc99187eacd39b14
Author: Antony Riakiotakis
Date:   Tue Jun 10 17:29:15 2014 +0300
https://developer.blender.org/rB6e7279752af01069cf7e6062bc99187eacd39b14

Fix undo after paint curve editing crashing on sculpt mode. Also fix bad
file write of paint curves.

===================================================================

M	source/blender/blenloader/intern/writefile.c
M	source/blender/editors/include/ED_sculpt.h
M	source/blender/editors/sculpt_paint/paint_curve.c
M	source/blender/editors/sculpt_paint/paint_image.c
M	source/blender/editors/sculpt_paint/paint_image_proj.c
M	source/blender/editors/sculpt_paint/paint_intern.h
M	source/blender/editors/sculpt_paint/paint_undo.c
M	source/blender/editors/sculpt_paint/sculpt_undo.c
M	source/blender/editors/space_image/image_ops.c

===================================================================

diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c
index b4e01b6..979a56b 100644
--- a/source/blender/blenloader/intern/writefile.c
+++ b/source/blender/blenloader/intern/writefile.c
@@ -2946,7 +2946,7 @@ static void write_paintcurves(WriteData *wd, ListBase *idbase)
 
 	for (pc = idbase->first; pc; pc = pc->id.next) {
 		if (pc->id.us > 0 || wd->current) {
-			writestruct(wd, ID_PC, "Palette", 1, pc);
+			writestruct(wd, ID_PC, "PaintCurve", 1, pc);
 
 			writestruct(wd, DATA, "PaintCurvePoint", pc->tot_points, pc->points);
 			if (pc->id.properties) IDP_WriteProperty(pc->id.properties, wd);
diff --git a/source/blender/editors/include/ED_sculpt.h b/source/blender/editors/include/ED_sculpt.h
index 015d8b1..792658d 100644
--- a/source/blender/editors/include/ED_sculpt.h
+++ b/source/blender/editors/include/ED_sculpt.h
@@ -59,6 +59,7 @@ void ED_keymap_paint(struct wmKeyConfig *keyconf);
 
 typedef void (*UndoRestoreCb)(struct bContext *C, struct ListBase *lb);
 typedef void (*UndoFreeCb)(struct ListBase *lb);
+typedef bool (*UndoCleanupCb)(struct bContext *C, struct ListBase *lb);
 
 int ED_undo_paint_step(struct bContext *C, int type, int step, const char *name);
 void ED_undo_paint_step_num(struct bContext *C, int type, int num);
@@ -66,7 +67,7 @@ const char *ED_undo_paint_get_name(struct bContext *C, int type, int nr, int *ac
 void ED_undo_paint_free(void);
 int ED_undo_paint_valid(int type, const char *name);
 bool ED_undo_paint_empty(int type);
-void ED_undo_paint_push_begin(int type, const char *name, UndoRestoreCb restore, UndoFreeCb free);
+void ED_undo_paint_push_begin(int type, const char *name, UndoRestoreCb restore, UndoFreeCb free, UndoCleanupCb cleanup);
 void ED_undo_paint_push_end(int type);
 
 /* image painting specific undo */
diff --git a/source/blender/editors/sculpt_paint/paint_curve.c b/source/blender/editors/sculpt_paint/paint_curve.c
index 2062576..c6d3174 100644
--- a/source/blender/editors/sculpt_paint/paint_curve.c
+++ b/source/blender/editors/sculpt_paint/paint_curve.c
@@ -142,7 +142,7 @@ static void paintcurve_undo_begin(bContext *C, wmOperator *op, PaintCurve *pc)
 
 
 	ED_undo_paint_push_begin(undo_stack_id, op->type->name,
-	                         paintcurve_undo_restore, paintcurve_undo_delete);
+	                         paintcurve_undo_restore, paintcurve_undo_delete, NULL);
 	lb = undo_paint_push_get_list(undo_stack_id);
 
 	uc = MEM_callocN(sizeof(*uc), "Undo_curve");
diff --git a/source/blender/editors/sculpt_paint/paint_image.c b/source/blender/editors/sculpt_paint/paint_image.c
index 5c7df32..32158f6 100644
--- a/source/blender/editors/sculpt_paint/paint_image.c
+++ b/source/blender/editors/sculpt_paint/paint_image.c
@@ -754,7 +754,7 @@ static PaintOperation *texture_paint_init(bContext *C, wmOperator *op, const flo
 
 	settings->imapaint.flag |= IMAGEPAINT_DRAWING;
 	ED_undo_paint_push_begin(UNDO_PAINT_IMAGE, op->type->name,
-	                         ED_image_undo_restore, ED_image_undo_free);
+	                         ED_image_undo_restore, ED_image_undo_free, NULL);
 
 	return pop;
 }
@@ -1540,7 +1540,7 @@ void PAINT_OT_brush_colors_flip(wmOperatorType *ot)
 void paint_bucket_fill(struct bContext *C, float color[3], wmOperator *op)
 {
 	ED_undo_paint_push_begin(UNDO_PAINT_IMAGE, op->type->name,
-	                      ED_image_undo_restore, ED_image_undo_free);
+	                      ED_image_undo_restore, ED_image_undo_free, NULL);
 
 	paint_2d_bucket_fill(C, color, NULL, NULL, NULL);
 
diff --git a/source/blender/editors/sculpt_paint/paint_image_proj.c b/source/blender/editors/sculpt_paint/paint_image_proj.c
index 6615b2e..fcf2456 100644
--- a/source/blender/editors/sculpt_paint/paint_image_proj.c
+++ b/source/blender/editors/sculpt_paint/paint_image_proj.c
@@ -4639,7 +4639,7 @@ static int texture_paint_camera_project_exec(bContext *C, wmOperator *op)
 	scene->toolsettings->imapaint.flag |= IMAGEPAINT_DRAWING;
 
 	ED_undo_paint_push_begin(UNDO_PAINT_IMAGE, op->type->name,
-	                         ED_image_undo_restore, ED_image_undo_free);
+	                         ED_image_undo_restore, ED_image_undo_free, NULL);
 
 	/* allocate and initialize spatial data structures */
 	project_paint_begin(&ps);
diff --git a/source/blender/editors/sculpt_paint/paint_intern.h b/source/blender/editors/sculpt_paint/paint_intern.h
index 52bb3b2..fde03c8 100644
--- a/source/blender/editors/sculpt_paint/paint_intern.h
+++ b/source/blender/editors/sculpt_paint/paint_intern.h
@@ -239,7 +239,6 @@ typedef enum BrushStrokeMode {
 /* paint_undo.c */
 struct ListBase *undo_paint_push_get_list(int type);
 void undo_paint_push_count_alloc(int type, int size);
-bool sculpt_undo_cleanup(struct bContext *C, struct ListBase *lb);
 
 /* paint_hide.c */
 
diff --git a/source/blender/editors/sculpt_paint/paint_undo.c b/source/blender/editors/sculpt_paint/paint_undo.c
index 5bd6526..653f6f5 100644
--- a/source/blender/editors/sculpt_paint/paint_undo.c
+++ b/source/blender/editors/sculpt_paint/paint_undo.c
@@ -51,19 +51,17 @@ typedef struct UndoElem {
 
 	UndoRestoreCb restore;
 	UndoFreeCb free;
+	UndoCleanupCb cleanup;
 } UndoElem;
 
-typedef bool (*UndoCleanupCb)(struct bContext *C, ListBase *lb);
-
 typedef struct UndoStack {
 	int type;
 	ListBase elems;
 	UndoElem *current;
-	UndoCleanupCb cleanup;
 } UndoStack;
 
-static UndoStack ImageUndoStack = {UNDO_PAINT_IMAGE, {NULL, NULL}, NULL, NULL};
-static UndoStack MeshUndoStack = {UNDO_PAINT_MESH, {NULL, NULL}, NULL, sculpt_undo_cleanup};
+static UndoStack ImageUndoStack = {UNDO_PAINT_IMAGE, {NULL, NULL}, NULL};
+static UndoStack MeshUndoStack = {UNDO_PAINT_MESH, {NULL, NULL}, NULL};
 
 /* Generic */
 
@@ -81,7 +79,7 @@ static void undo_elem_free(UndoStack *UNUSED(stack), UndoElem *uel)
 	}
 }
 
-static void undo_stack_push_begin(UndoStack *stack, const char *name, UndoRestoreCb restore, UndoFreeCb free)
+static void undo_stack_push_begin(UndoStack *stack, const char *name, UndoRestoreCb restore, UndoFreeCb free, UndoCleanupCb cleanup)
 {
 	UndoElem *uel;
 	int nr;
@@ -101,6 +99,7 @@ static void undo_stack_push_begin(UndoStack *stack, const char *name, UndoRestor
 	stack->current = uel = MEM_callocN(sizeof(UndoElem), "undo file");
 	uel->restore = restore;
 	uel->free = free;
+	uel->cleanup = cleanup;
 	BLI_addtail(&stack->elems, uel);
 
 	/* name can be a dynamic string */
@@ -179,25 +178,24 @@ static void undo_stack_cleanup(UndoStack *stack, bContext *C)
 	UndoElem *uel = stack->elems.first;
 	bool stack_reset = false;
 
-	if (stack->cleanup) {
-		while (uel) {
-			if (stack->cleanup(C, &uel->elems)) {
-				UndoElem *uel_tmp = uel->next;
-				if (stack->current == uel) {
-					stack->current = NULL;
-					stack_reset = true;
-				}
-				undo_elem_free(stack, uel);
-				BLI_freelinkN(&stack->elems, uel);
-				uel = uel_tmp;
+	while (uel) {
+		if (uel->cleanup && uel->cleanup(C, &uel->elems)) {
+			UndoElem *uel_tmp = uel->next;
+			if (stack->current == uel) {
+				stack->current = NULL;
+				stack_reset = true;
 			}
-			else
-				uel = uel->next;
-		}
-		if (stack_reset) {
-			stack->current = stack->elems.last;
+			undo_elem_free(stack, uel);
+			BLI_freelinkN(&stack->elems, uel);
+			uel = uel_tmp;
 		}
+		else
+			uel = uel->next;
 	}
+	if (stack_reset) {
+		stack->current = stack->elems.last;
+	}
+
 }
 
 static int undo_stack_step(bContext *C, UndoStack *stack, int step, const char *name)
@@ -255,12 +253,12 @@ static void undo_stack_free(UndoStack *stack)
 
 /* Exported Functions */
 
-void ED_undo_paint_push_begin(int type, const char *name, UndoRestoreCb restore, UndoFreeCb free)
+void ED_undo_paint_push_begin(int type, const char *name, UndoRestoreCb restore, UndoFreeCb free , UndoCleanupCb cleanup)
 {
 	if (type == UNDO_PAINT_IMAGE)
-		undo_stack_push_begin(&ImageUndoStack, name, restore, free);
+		undo_stack_push_begin(&ImageUndoStack, name, restore, free, cleanup);
 	else if (type == UNDO_PAINT_MESH)
-		undo_stack_push_begin(&MeshUndoStack, name, restore, free);
+		undo_stack_push_begin(&MeshUndoStack, name, restore, free, cleanup);
 }
 
 ListBase *undo_paint_push_get_list(int type)
diff --git a/source/blender/editors/sculpt_paint/sculpt_undo.c b/source/blender/editors/sculpt_paint/sculpt_undo.c
index fa398e3..a61e4ef 100644
--- a/source/blender/editors/sculpt_paint/sculpt_undo.c
+++ b/source/blender/editors/sculpt_paint/sculpt_undo.c
@@ -542,7 +542,7 @@ static void sculpt_undo_free(ListBase *lb)
 	}
 }
 
-bool sculpt_undo_cleanup(bContext *C, ListBase *lb)
+static bool sculpt_undo_cleanup(bContext *C, ListBase *lb)
 {
 	Object *ob = CTX_data_active_object(C);
 	SculptUndoNode *unode;
@@ -550,10 +550,8 @@ bool sculpt_undo_cleanup(bContext *C, ListBase *lb)
 	unode = lb->first;
 
 	if (unode && strcmp(unode->idname, ob->id.name) != 0) {
-		for (unode = lb->first; unode; unode = unode->next) {
-			if (unode->bm_entry)
-				BM_log_cleanup_entry(unode->bm_entry);
-		}
+		if (unode->bm_entry)
+			BM_log_cleanup_entry(unode->bm_entry);
 
 		return true;
 	}
@@ -880,7 +878,7 @@ SculptUndoNode *sculpt_undo_push_node(Object *ob, PBVHNode *node,
 void sculpt_undo_push_begin(const char *name)
 {
 	ED_undo_paint_push_begin(UNDO_PAINT_MESH, name,
-	                         sculpt_undo_restore, sculpt_undo_free);
+	                         sculpt_undo_restore, sculpt_undo_free, sculpt_undo_cleanup);
 }
 
 void sculpt_undo_push_end(void)
diff --git a/source/blender/editors/space_image/image_ops.c b/source/blender/editors/space_image/image_ops.c
index 2d1e538..7421e39 100644
--- a/source/blender/editors/space_image/image_ops.c
+++ b/source/blender/editors/space_image/image_ops.c
@@ -2043,7 +2043,7 @@ static int image_invert_exec(bContext *C, wmOperator *op)
 
 	if (support_undo) {
 		ED_undo_paint_push_begin(UNDO_PAINT_IMAGE, op->type->name,
-		                         ED_image_undo_restore, ED_image_undo_free);
+		                         ED_image_undo_restore, ED_image_undo_free, NULL);
 		/* not strictly needed, because we only imapaint_dirty_region to invalidate all tiles
 		 * but better do this right in case someone copies this for a tool that uses partial redraw better */
 		ED_imapaint_clear_partial_redraw();




More information about the Bf-blender-cvs mailing list