From 0e51defcf42e1cb231d36da9ecc2cc0fbe6ae505 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Mon, 7 Mar 2022 21:47:00 +1100 Subject: Fix T95591: Crash on drawing with measure tool with tweak fallback tool Using press to activate the Tweak tool doesn't work well when used a fallback tool as the drag event is often used by the current tool - making it impossible not to select when dragging (unless the fallback tool is disabled entirely). Resolve this by using CLICK events when the Tweak tool is used as a fallback. Even though this avoids the crash, check for null-pointer de-reference since changes to the key-map shouldn't cause operators to crash. Note that the ability for operators to access a gizmo before it's fully initialized is a more general problem that should be addressed, but out of scope for a bug-fix. Reviewed By: zeddb, JulienKaspar, Severin Maniphest Tasks: T95591 Ref D14231 --- .../editors/space_view3d/view3d_gizmo_ruler.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'source/blender/editors/space_view3d/view3d_gizmo_ruler.c') diff --git a/source/blender/editors/space_view3d/view3d_gizmo_ruler.c b/source/blender/editors/space_view3d/view3d_gizmo_ruler.c index 1082483dcd7..adcb101bca9 100644 --- a/source/blender/editors/space_view3d/view3d_gizmo_ruler.c +++ b/source/blender/editors/space_view3d/view3d_gizmo_ruler.c @@ -469,6 +469,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; +} + /** \} */ /* -------------------------------------------------------------------- */ @@ -1308,6 +1321,10 @@ 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; + } + /* Create new line */ RulerItem *ruler_item; ruler_item = ruler_item_add(gzgroup); @@ -1383,6 +1400,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; -- cgit v1.2.3