fix for crash executing sculpt via python.
authorCampbell Barton <ideasman42@gmail.com>
Wed, 4 May 2011 03:34:55 +0000 (03:34 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Wed, 4 May 2011 03:34:55 +0000 (03:34 +0000)
source/blender/editors/sculpt_paint/paint_stroke.c
source/blender/editors/sculpt_paint/sculpt.c

index b63c2973758189fa3299663513095cf4d8b1c7b2..e7b625054175232256a5c4eb2876f67d4c950f0c 100644 (file)
@@ -896,11 +896,20 @@ int paint_stroke_exec(bContext *C, wmOperator *op)
 {
        PaintStroke *stroke = op->customdata;
 
+       /* only when executed for the first time */
+       if(stroke->stroke_started == 0) {
+               /* XXX stroke->last_mouse_position is unset, this may cause problems */
+               stroke->test_start(C, op, NULL);
+               stroke->stroke_started= 1;
+       }
+
        RNA_BEGIN(op->ptr, itemptr, "stroke") {
                stroke->update_step(C, stroke, &itemptr);
        }
        RNA_END;
 
+       stroke->done(C, stroke);
+
        MEM_freeN(stroke);
        op->customdata = NULL;
 
index e4385131db17b7eb883f1c8ac1383b83ce6ad262..1ed4764c629ec9491abc4efbea638bc0a431d72c 100644 (file)
@@ -3462,8 +3462,9 @@ static int over_mesh(bContext *C, struct wmOperator *op, float x, float y)
 static int sculpt_stroke_test_start(bContext *C, struct wmOperator *op,
                                        wmEvent *event)
 {
-       /* Don't start the stroke until mouse goes over the mesh */
-       if(over_mesh(C, op, event->x, event->y)) {
+       /* Don't start the stroke until mouse goes over the mesh.
+        * note: event will only be null when re-executing the saved stroke. */
+       if(event==NULL || over_mesh(C, op, event->x, event->y)) {
                Object *ob = CTX_data_active_object(C);
                SculptSession *ss = ob->sculpt;
                Sculpt *sd = CTX_data_tool_settings(C)->sculpt;
@@ -3604,22 +3605,15 @@ static int sculpt_brush_stroke_invoke(bContext *C, wmOperator *op, wmEvent *even
 
 static int sculpt_brush_stroke_exec(bContext *C, wmOperator *op)
 {
-       Sculpt *sd = CTX_data_tool_settings(C)->sculpt;
-       SculptSession *ss = CTX_data_active_object(C)->sculpt;
-
        if(!sculpt_brush_stroke_init(C, op->reports))
                return OPERATOR_CANCELLED;
 
        op->customdata = paint_stroke_new(C, sculpt_stroke_get_location, sculpt_stroke_test_start,
                                          sculpt_stroke_update_step, sculpt_stroke_done, 0);
 
-       sculpt_update_cache_invariants(C, sd, ss, op, NULL);
-
+       /* frees op->customdata */
        paint_stroke_exec(C, op);
 
-       sculpt_flush_update(C);
-       sculpt_cache_free(ss->cache);
-
        return OPERATOR_FINISHED;
 }