From 41dbd19b4d19daada4f0189107b4f3aa9a043869 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Wed, 4 May 2011 03:34:55 +0000 Subject: fix for crash executing sculpt via python. --- source/blender/editors/sculpt_paint/paint_stroke.c | 9 +++++++++ source/blender/editors/sculpt_paint/sculpt.c | 14 ++++---------- 2 files changed, 13 insertions(+), 10 deletions(-) (limited to 'source/blender/editors/sculpt_paint') diff --git a/source/blender/editors/sculpt_paint/paint_stroke.c b/source/blender/editors/sculpt_paint/paint_stroke.c index b63c2973758..e7b62505417 100644 --- a/source/blender/editors/sculpt_paint/paint_stroke.c +++ b/source/blender/editors/sculpt_paint/paint_stroke.c @@ -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; diff --git a/source/blender/editors/sculpt_paint/sculpt.c b/source/blender/editors/sculpt_paint/sculpt.c index e4385131db1..1ed4764c629 100644 --- a/source/blender/editors/sculpt_paint/sculpt.c +++ b/source/blender/editors/sculpt_paint/sculpt.c @@ -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; } -- cgit v1.2.3