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
This commit is contained in:
Campbell Barton 2022-03-07 21:47:00 +11:00
parent 72e20785e1
commit 0e51defcf4
Notes: blender-bot 2023-02-14 02:41:05 +01:00
Referenced by commit 95cc5c6081, Fix T96885: Drag Fallback on Tweak is using Move instead
Referenced by issue #95591, Crash on drawing with measure tool
2 changed files with 34 additions and 9 deletions

View File

@ -442,13 +442,18 @@ def _template_items_change_frame(params):
# Tool System Templates
def _template_items_tool_select(params, operator, cursor_operator, *, extend):
def _template_items_tool_select(params, operator, cursor_operator, fallback, *, extend):
if params.select_mouse == 'LEFTMOUSE':
# Immediate select without quick delay.
# By default use 'PRESS' for immediate select without quick delay.
# Fallback key-maps 'CLICK' since 'PRESS' events passes through (allowing either click or drag).
#
# NOTE: When the active (non-fallback) tool uses a key-map that activates it's primary tool on drag,
# it's important that this key-map uses click and not press. Otherwise it becomes impossible to use
# the tool without selecting elements under the cursor.
return [
(operator, {"type": 'LEFTMOUSE', "value": 'PRESS'},
(operator, {"type": 'LEFTMOUSE', "value": 'CLICK' if fallback else 'PRESS'},
{"properties": [("deselect_all", True)]}),
(operator, {"type": 'LEFTMOUSE', "value": 'PRESS', "shift": True},
(operator, {"type": 'LEFTMOUSE', "value": 'CLICK' if fallback else 'PRESS', "shift": True},
{"properties": [(extend, True)]}),
]
else:
@ -6283,7 +6288,7 @@ def km_image_editor_tool_uv_select(params, *, fallback):
{"space_type": 'IMAGE_EDITOR', "region_type": 'WINDOW'},
{"items": [
*([] if (fallback and (params.select_mouse == 'RIGHTMOUSE')) else _template_items_tool_select(
params, "uv.select", "uv.cursor_set", extend="extend")),
params, "uv.select", "uv.cursor_set", fallback, extend="extend")),
*([] if (not params.use_fallback_tool_rmb) else _template_uv_select(
type=params.select_mouse, value=params.select_mouse_value, legacy=params.legacy)),
]},
@ -6490,7 +6495,7 @@ def km_3d_view_tool_select(params, *, fallback):
{"space_type": 'VIEW_3D', "region_type": 'WINDOW'},
{"items": [
*([] if (fallback and (params.select_mouse == 'RIGHTMOUSE')) else _template_items_tool_select(
params, "view3d.select", "view3d.cursor3d", extend="toggle")),
params, "view3d.select", "view3d.cursor3d", fallback, extend="toggle")),
*([] if (not params.use_fallback_tool_rmb) else _template_view3d_select(
type=params.select_mouse, value=params.select_mouse_value, legacy=params.legacy, exclude_mod="ctrl")),
]},
@ -7402,7 +7407,7 @@ def km_3d_view_tool_edit_gpencil_select(params, *, fallback):
{"space_type": 'VIEW_3D', "region_type": 'WINDOW'},
{"items": [
*([] if (fallback and (params.select_mouse == 'RIGHTMOUSE')) else _template_items_tool_select(
params, "gpencil.select", "view3d.cursor3d", extend="toggle")),
params, "gpencil.select", "view3d.cursor3d", fallback, extend="toggle")),
*([] if (not params.use_fallback_tool_rmb) else _template_view3d_gpencil_select(
type=params.select_mouse, value=params.select_mouse_value, legacy=params.legacy)),
]},
@ -7540,7 +7545,7 @@ def km_3d_view_tool_sculpt_gpencil_select(params):
return (
"3D View Tool: Sculpt Gpencil, Tweak",
{"space_type": 'VIEW_3D', "region_type": 'WINDOW'},
{"items": _template_items_tool_select(params, "gpencil.select", "view3d.cursor3d", extend="toggle")},
{"items": _template_items_tool_select(params, "gpencil.select", "view3d.cursor3d", False, extend="toggle")},
)
@ -7580,7 +7585,7 @@ def km_sequencer_editor_tool_generic_select(params, *, fallback):
{"space_type": 'SEQUENCE_EDITOR', "region_type": 'WINDOW'},
{"items": [
*([] if (fallback and (params.select_mouse == 'RIGHTMOUSE')) else _template_items_tool_select(
params, "sequencer.select", "sequencer.cursor_set", extend="toggle")),
params, "sequencer.select", "sequencer.cursor_set", fallback, extend="toggle")),
*([] if (not params.use_fallback_tool_rmb) else _template_sequencer_preview_select(
type=params.select_mouse, value=params.select_mouse_value, legacy=params.legacy)),

View File

@ -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;