diff options
Diffstat (limited to 'source/blender/editors/space_view3d/view3d_gizmo_ruler.c')
-rw-r--r-- | source/blender/editors/space_view3d/view3d_gizmo_ruler.c | 33 |
1 files changed, 29 insertions, 4 deletions
diff --git a/source/blender/editors/space_view3d/view3d_gizmo_ruler.c b/source/blender/editors/space_view3d/view3d_gizmo_ruler.c index 9b954cd817b..3a8a28dc2a1 100644 --- a/source/blender/editors/space_view3d/view3d_gizmo_ruler.c +++ b/source/blender/editors/space_view3d/view3d_gizmo_ruler.c @@ -455,6 +455,19 @@ static bool view3d_ruler_item_mousemove(const bContext *C, return false; } +/** + * When the gizmo-group has been created immediately before running an operator + * to manipulate rulers, it's possible the new gizmo-group has not yet been initialized. + * in 3.0 this happened because left-click drag would both select and add a new ruler, + * significantly increasing the likelihood of this happening. + * Workaround this crash by checking the gizmo's custom-data has not been cleared. + * The key-map has also been modified not to trigger this bug, see T95591. + */ +static bool gizmo_ruler_check_for_operator(const wmGizmoGroup *gzgroup) +{ + return gzgroup->customdata != NULL; +} + /** \} */ /* -------------------------------------------------------------------- */ @@ -1069,7 +1082,8 @@ static int gizmo_ruler_invoke(bContext *C, wmGizmo *gz, const wmEvent *event) ARegion *region = ruler_info->region; - const float mval_fl[2] = {UNPACK2(event->mval)}; + float mval_fl[2]; + WM_event_drag_start_mval_fl(event, region, mval_fl); #ifdef USE_AXIS_CONSTRAINTS ruler_info->constrain_axis = CONSTRAIN_AXIS_NONE; @@ -1294,13 +1308,21 @@ static int view3d_ruler_add_invoke(bContext *C, wmOperator *op, const wmEvent *e wmGizmoGroup *gzgroup = WM_gizmomap_group_find(gzmap, view3d_gzgt_ruler_id); const bool use_depth = (v3d->shading.type >= OB_SOLID); + if (!gizmo_ruler_check_for_operator(gzgroup)) { + return OPERATOR_CANCELLED; + } + + int mval[2]; + WM_event_drag_start_mval(event, region, mval); + /* Create new line */ RulerItem *ruler_item; ruler_item = ruler_item_add(gzgroup); /* This is a little weak, but there is no real good way to tweak directly. */ WM_gizmo_highlight_set(gzmap, &ruler_item->gz); - if (WM_operator_name_call(C, "GIZMOGROUP_OT_gizmo_tweak", WM_OP_INVOKE_REGION_WIN, NULL) == + if (WM_operator_name_call( + C, "GIZMOGROUP_OT_gizmo_tweak", WM_OP_INVOKE_REGION_WIN, NULL, event) == OPERATOR_RUNNING_MODAL) { RulerInfo *ruler_info = gzgroup->customdata; RulerInteraction *inter = ruler_item->gz.interaction_data; @@ -1312,7 +1334,7 @@ static int view3d_ruler_add_invoke(bContext *C, wmOperator *op, const wmEvent *e depsgraph, ruler_info, ruler_item, - event->mval, + mval, false #ifndef USE_SNAP_DETECT_FROM_KEYMAP_HACK , @@ -1327,7 +1349,7 @@ static int view3d_ruler_add_invoke(bContext *C, wmOperator *op, const wmEvent *e else { negate_v3_v3(inter->drag_start_co, rv3d->ofs); copy_v3_v3(ruler_item->co[0], inter->drag_start_co); - view3d_ruler_item_project(ruler_info, ruler_item->co[0], event->mval); + view3d_ruler_item_project(ruler_info, ruler_item->co[0], mval); } copy_v3_v3(ruler_item->co[2], ruler_item->co[0]); @@ -1369,6 +1391,9 @@ static int view3d_ruler_remove_invoke(bContext *C, wmOperator *op, const wmEvent wmGizmoMap *gzmap = region->gizmo_map; wmGizmoGroup *gzgroup = WM_gizmomap_group_find(gzmap, view3d_gzgt_ruler_id); if (gzgroup) { + if (!gizmo_ruler_check_for_operator(gzgroup)) { + return OPERATOR_CANCELLED; + } RulerInfo *ruler_info = gzgroup->customdata; if (ruler_info->item_active) { RulerItem *ruler_item = ruler_info->item_active; |