[Bf-blender-cvs] [6810deb5215] blender-v3.3-release: Fix T101062: sculpt curves crash using a paintcurve brush

Philipp Oeser noreply at git.blender.org
Mon Nov 28 14:21:54 CET 2022


Commit: 6810deb5215df3ee7d92d7972988092f1aab5eae
Author: Philipp Oeser
Date:   Thu Sep 29 12:57:48 2022 +0200
Branches: blender-v3.3-release
https://developer.blender.org/rB6810deb5215df3ee7d92d7972988092f1aab5eae

Fix T101062: sculpt curves crash using a paintcurve brush

For one, paintcurves were not considered in curves sculpt mode at all
(so you couldnt draw them). This is now enabled.

And the second issue was that since curves sculpt mode uses the reguar
paint_stroke_modal() [which handles paintcurves], this was actually
excuted, freeing the PaintStroke from SculptCurvesBrushStrokeData (but
not the CurvesSculptStrokeOperation) and immediately return
OPERATOR_FINISHED from modal (resulting in a double MEM_delete of
SculptCurvesBrushStrokeData -- in both invoke and modal).

There might be better ways to handle the memory free, for now the double
freeing is prevented by setting the operator customdata to NULL (and
check for that later).

Maniphest Tasks: T101062

Differential Revision: https://developer.blender.org/D16099

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

M	source/blender/editors/sculpt_paint/curves_sculpt_ops.cc
M	source/blender/editors/sculpt_paint/paint_curve.c

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

diff --git a/source/blender/editors/sculpt_paint/curves_sculpt_ops.cc b/source/blender/editors/sculpt_paint/curves_sculpt_ops.cc
index 4ae4149a2a0..7a61a9229e6 100644
--- a/source/blender/editors/sculpt_paint/curves_sculpt_ops.cc
+++ b/source/blender/editors/sculpt_paint/curves_sculpt_ops.cc
@@ -220,8 +220,10 @@ static int sculpt_curves_stroke_invoke(bContext *C, wmOperator *op, const wmEven
 
   int return_value = op->type->modal(C, op, event);
   if (return_value == OPERATOR_FINISHED) {
-    paint_stroke_free(C, op, op_data->stroke);
-    MEM_delete(op_data);
+    if (op->customdata != nullptr) {
+      paint_stroke_free(C, op, op_data->stroke);
+      MEM_delete(op_data);
+    }
     return OPERATOR_FINISHED;
   }
 
@@ -236,16 +238,19 @@ static int sculpt_curves_stroke_modal(bContext *C, wmOperator *op, const wmEvent
   int return_value = paint_stroke_modal(C, op, event, &op_data->stroke);
   if (ELEM(return_value, OPERATOR_FINISHED, OPERATOR_CANCELLED)) {
     MEM_delete(op_data);
+    op->customdata = nullptr;
   }
   return return_value;
 }
 
 static void sculpt_curves_stroke_cancel(bContext *C, wmOperator *op)
 {
-  SculptCurvesBrushStrokeData *op_data = static_cast<SculptCurvesBrushStrokeData *>(
-      op->customdata);
-  paint_stroke_cancel(C, op, op_data->stroke);
-  MEM_delete(op_data);
+  if (op->customdata != nullptr) {
+    SculptCurvesBrushStrokeData *op_data = static_cast<SculptCurvesBrushStrokeData *>(
+        op->customdata);
+    paint_stroke_cancel(C, op, op_data->stroke);
+    MEM_delete(op_data);
+  }
 }
 
 static void SCULPT_CURVES_OT_brush_stroke(struct wmOperatorType *ot)
diff --git a/source/blender/editors/sculpt_paint/paint_curve.c b/source/blender/editors/sculpt_paint/paint_curve.c
index 22d6626ab16..26f76d46f85 100644
--- a/source/blender/editors/sculpt_paint/paint_curve.c
+++ b/source/blender/editors/sculpt_paint/paint_curve.c
@@ -44,7 +44,7 @@ bool paint_curve_poll(bContext *C)
   RegionView3D *rv3d = CTX_wm_region_view3d(C);
   SpaceImage *sima;
 
-  if (rv3d && !(ob && ((ob->mode & OB_MODE_ALL_PAINT) != 0))) {
+  if (rv3d && !(ob && ((ob->mode & (OB_MODE_ALL_PAINT | OB_MODE_SCULPT_CURVES)) != 0))) {
     return false;
   }
 
@@ -676,6 +676,9 @@ static int paintcurve_draw_exec(bContext *C, wmOperator *UNUSED(op))
     case PAINT_MODE_SCULPT:
       name = "SCULPT_OT_brush_stroke";
       break;
+    case PAINT_MODE_SCULPT_CURVES:
+      name = "SCULPT_CURVES_OT_brush_stroke";
+      break;
     default:
       return OPERATOR_PASS_THROUGH;
   }



More information about the Bf-blender-cvs mailing list