[Bf-blender-cvs] [e8c24ee] master: Fix memory leak running project-paint from Python

Campbell Barton noreply at git.blender.org
Tue Feb 23 14:40:49 CET 2016


Commit: e8c24ee0d9262fe648f4bd8f13e1a2f1f88ae050
Author: Campbell Barton
Date:   Wed Feb 24 00:31:46 2016 +1100
Branches: master
https://developer.blender.org/rBe8c24ee0d9262fe648f4bd8f13e1a2f1f88ae050

Fix memory leak running project-paint from Python

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

M	source/blender/editors/sculpt_paint/paint_image.c
M	source/blender/editors/sculpt_paint/paint_stroke.c

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

diff --git a/source/blender/editors/sculpt_paint/paint_image.c b/source/blender/editors/sculpt_paint/paint_image.c
index 377ba3d..4d82553 100644
--- a/source/blender/editors/sculpt_paint/paint_image.c
+++ b/source/blender/editors/sculpt_paint/paint_image.c
@@ -954,7 +954,6 @@ static int paint_invoke(bContext *C, wmOperator *op, const wmEvent *event)
 
 static int paint_exec(bContext *C, wmOperator *op)
 {
-	PaintOperation *pop;
 	PropertyRNA *strokeprop;
 	PointerRNA firstpoint;
 	float mouse[2];
@@ -966,18 +965,12 @@ static int paint_exec(bContext *C, wmOperator *op)
 
 	RNA_float_get_array(&firstpoint, "mouse", mouse);
 
-	if (!(pop = texture_paint_init(C, op, mouse))) {
-		return OPERATOR_CANCELLED;
-	}
-
 	op->customdata = paint_stroke_new(C, op, NULL, paint_stroke_test_start,
 	                                  paint_stroke_update_step,
 	                                  paint_stroke_redraw,
 	                                  paint_stroke_done, 0);
 	/* frees op->customdata */
-	paint_stroke_exec(C, op);
-
-	return OPERATOR_FINISHED;
+	return paint_stroke_exec(C, op);
 }
 
 void PAINT_OT_image_paint(wmOperatorType *ot)
diff --git a/source/blender/editors/sculpt_paint/paint_stroke.c b/source/blender/editors/sculpt_paint/paint_stroke.c
index 31d4e6b..65857cc 100644
--- a/source/blender/editors/sculpt_paint/paint_stroke.c
+++ b/source/blender/editors/sculpt_paint/paint_stroke.c
@@ -1237,23 +1237,33 @@ int paint_stroke_exec(bContext *C, wmOperator *op)
 {
 	PaintStroke *stroke = op->customdata;
 
-	RNA_BEGIN (op->ptr, itemptr, "stroke")
-	{
-		/* only when executed for the first time */
-		if (stroke->stroke_started == 0) {
-			float mval[2];
-			RNA_float_get_array(&itemptr, "mouse", mval);
-			stroke->test_start(C, op, mval);
-			stroke->stroke_started = 1;
+	/* only when executed for the first time */
+	if (stroke->stroke_started == 0) {
+		PropertyRNA *strokeprop;
+		PointerRNA firstpoint;
+		float mouse[2];
+
+		strokeprop = RNA_struct_find_property(op->ptr, "stroke");
+
+		if (RNA_property_collection_lookup_int(op->ptr, strokeprop, 0, &firstpoint)) {
+			RNA_float_get_array(&firstpoint, "mouse", mouse);
+			stroke->stroke_started = stroke->test_start(C, op, mouse);
 		}
+	}
 
-		stroke->update_step(C, stroke, &itemptr);
+	if (stroke->stroke_started) {
+		RNA_BEGIN (op->ptr, itemptr, "stroke")
+		{
+			stroke->update_step(C, stroke, &itemptr);
+		}
+		RNA_END;
 	}
-	RNA_END;
+
+	bool ok = (stroke->stroke_started != 0);
 
 	stroke_done(C, op);
 
-	return OPERATOR_FINISHED;
+	return ok ? OPERATOR_FINISHED : OPERATOR_CANCELLED;
 }
 
 void paint_stroke_cancel(bContext *C, wmOperator *op)




More information about the Bf-blender-cvs mailing list