From 6d749db0c218962ca37d26f481ed28139b299014 Mon Sep 17 00:00:00 2001 From: Pratik Borhade Date: Thu, 13 Feb 2025 11:53:03 +0100 Subject: [PATCH 1/3] Fix #134468: Grease Pencil: Primtive tools considering mouse drag threshold This is due to the click_drag event assigned for primitives. Event types that are not "PRESS" are forwarded to drag_queue then waits until `WM_event_drag_test_with_delta/WM_event_drag_test` is true i.e. mouse threshold value. Pull Request: https://projects.blender.org/blender/blender/pulls/134480 --- .../presets/keyconfig/keymap_data/blender_default.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/scripts/presets/keyconfig/keymap_data/blender_default.py b/scripts/presets/keyconfig/keymap_data/blender_default.py index 8c42b6d6892..f47f4a6c935 100644 --- a/scripts/presets/keyconfig/keymap_data/blender_default.py +++ b/scripts/presets/keyconfig/keymap_data/blender_default.py @@ -7931,7 +7931,7 @@ def km_3d_view_tool_paint_grease_pencil_primitive_line(params): "3D View Tool: Paint Grease Pencil, Line", {"space_type": 'VIEW_3D', "region_type": 'WINDOW'}, {"items": [ - ("grease_pencil.primitive_line", params.tool_maybe_tweak_event, + ("grease_pencil.primitive_line", {"type": 'LEFTMOUSE', "value": 'PRESS'}, {"properties": []}), ("grease_pencil.primitive_line", {"type": 'LEFTMOUSE', "value": 'PRESS', "shift": True}, {"properties": []}), @@ -7965,7 +7965,7 @@ def km_3d_view_tool_paint_grease_pencil_primitive_box(params): "3D View Tool: Paint Grease Pencil, Box", {"space_type": 'VIEW_3D', "region_type": 'WINDOW'}, {"items": [ - ("grease_pencil.primitive_box", params.tool_maybe_tweak_event, + ("grease_pencil.primitive_box", {"type": 'LEFTMOUSE', "value": 'PRESS'}, {"properties": []}), ("grease_pencil.primitive_box", {"type": 'LEFTMOUSE', "value": 'PRESS', "shift": True}, {"properties": []}), @@ -7983,7 +7983,7 @@ def km_3d_view_tool_paint_grease_pencil_primitive_circle(params): "3D View Tool: Paint Grease Pencil, Circle", {"space_type": 'VIEW_3D', "region_type": 'WINDOW'}, {"items": [ - ("grease_pencil.primitive_circle", params.tool_maybe_tweak_event, + ("grease_pencil.primitive_circle", {"type": 'LEFTMOUSE', "value": 'PRESS'}, {"properties": []}), ("grease_pencil.primitive_circle", {"type": 'LEFTMOUSE', "value": 'PRESS', "shift": True}, {"properties": []}), @@ -8001,7 +8001,7 @@ def km_3d_view_tool_paint_grease_pencil_primitive_arc(params): "3D View Tool: Paint Grease Pencil, Arc", {"space_type": 'VIEW_3D', "region_type": 'WINDOW'}, {"items": [ - ("grease_pencil.primitive_arc", params.tool_maybe_tweak_event, + ("grease_pencil.primitive_arc", {"type": 'LEFTMOUSE', "value": 'PRESS'}, {"properties": []}), ("grease_pencil.primitive_arc", {"type": 'LEFTMOUSE', "value": 'PRESS', "shift": True}, {"properties": []}), @@ -8019,7 +8019,7 @@ def km_3d_view_tool_paint_grease_pencil_primitive_curve(params): "3D View Tool: Paint Grease Pencil, Curve", {"space_type": 'VIEW_3D', "region_type": 'WINDOW'}, {"items": [ - ("grease_pencil.primitive_curve", params.tool_maybe_tweak_event, + ("grease_pencil.primitive_curve", {"type": 'LEFTMOUSE', "value": 'PRESS'}, {"properties": []}), # Lasso select ("grease_pencil.select_lasso", From ef844badd630b55ddcc3e5cbf2cd1f1ccc622f03 Mon Sep 17 00:00:00 2001 From: YimingWu Date: Thu, 13 Feb 2025 12:45:53 +0100 Subject: [PATCH 2/3] Fix #134482: Grease Pencil: Correct mask for stroke interpolation Selection mask is included in the stroke interpolation tool in 297b97f2df36248408bbbbde12600b9370a65642, however sometimes there will be mismatches for when start/end curve count isn't the same. This fix ensures that the interpolation operator only works on the max amount of curves that can fit in both start and end side of the interpolation. Pull Request: https://projects.blender.org/blender/blender/pulls/134484 --- .../sculpt_paint/grease_pencil_interpolate.cc | 4 ++-- .../geometry/intern/interpolate_curves.cc | 17 ++++++++++++----- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/source/blender/editors/sculpt_paint/grease_pencil_interpolate.cc b/source/blender/editors/sculpt_paint/grease_pencil_interpolate.cc index 42fdc0db236..cf42d03e154 100644 --- a/source/blender/editors/sculpt_paint/grease_pencil_interpolate.cc +++ b/source/blender/editors/sculpt_paint/grease_pencil_interpolate.cc @@ -287,10 +287,10 @@ static bool find_curve_mapping_from_index(const GreasePencil &grease_pencil, } /* Discard additional elements of the larger selection. */ if (from_selection.size() > to_selection.size()) { - from_selection.slice(0, to_selection.size()); + from_selection = from_selection.slice(0, to_selection.size()); } else if (to_selection.size() > from_selection.size()) { - to_selection.slice(0, from_selection.size()); + to_selection = to_selection.slice(0, from_selection.size()); } /* By default: copy the "from" curve and ignore the "to" curve. */ diff --git a/source/blender/geometry/intern/interpolate_curves.cc b/source/blender/geometry/intern/interpolate_curves.cc index 73b58bd4edb..b00795b2715 100644 --- a/source/blender/geometry/intern/interpolate_curves.cc +++ b/source/blender/geometry/intern/interpolate_curves.cc @@ -455,17 +455,24 @@ void interpolate_curves_with_samples(const CurvesGeometry &from_curves, CD_PROP_FLOAT2, CD_PROP_FLOAT3); if (can_mix_attribute && !src_from.is_empty() && !src_to.is_empty()) { + const int max_curves = std::min(dst_curve_mask.min_array_size(), + std::min(src_from.size(), src_to.size())); + const IndexMask safe_dst_curve_mask = dst_curve_mask.slice_content(0, max_curves); GArray<> from_samples(dst.type(), dst.size()); GArray<> to_samples(dst.type(), dst.size()); - array_utils::copy(GVArray::ForSpan(src_from), dst_curve_mask, from_samples); - array_utils::copy(GVArray::ForSpan(src_to), dst_curve_mask, to_samples); - mix_arrays(from_samples, to_samples, mix_factors, dst_curve_mask, dst); + array_utils::copy(GVArray::ForSpan(src_from), safe_dst_curve_mask, from_samples); + array_utils::copy(GVArray::ForSpan(src_to), safe_dst_curve_mask, to_samples); + mix_arrays(from_samples, to_samples, mix_factors, safe_dst_curve_mask, dst); } else if (!src_from.is_empty()) { - array_utils::copy(GVArray::ForSpan(src_from), dst_curve_mask, dst); + const int max_curves = std::min(dst_curve_mask.min_array_size(), src_from.size()); + const IndexMask safe_dst_curve_mask = dst_curve_mask.slice_content(0, max_curves); + array_utils::copy(GVArray::ForSpan(src_from), safe_dst_curve_mask, dst); } else if (!src_to.is_empty()) { - array_utils::copy(GVArray::ForSpan(src_to), dst_curve_mask, dst); + const int max_curves = std::min(dst_curve_mask.min_array_size(), src_to.size()); + const IndexMask safe_dst_curve_mask = dst_curve_mask.slice_content(0, max_curves); + array_utils::copy(GVArray::ForSpan(src_to), safe_dst_curve_mask, dst); } } From 700db42976b6dacc637cfd1e29cbf419bba14183 Mon Sep 17 00:00:00 2001 From: Bastien Montagne Date: Thu, 13 Feb 2025 13:00:24 +0100 Subject: [PATCH 3/3] Fix (unreported) invalid C-style allocation/freeing on non-trivial data. `tGPsdata` embeds a `PointerRNA` member, which makes it non-trivial, and requires it to use new/delete C++-style allocation handling. --- source/blender/editors/gpencil_legacy/annotate_paint.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/source/blender/editors/gpencil_legacy/annotate_paint.cc b/source/blender/editors/gpencil_legacy/annotate_paint.cc index 2720252c8cb..109adac3056 100644 --- a/source/blender/editors/gpencil_legacy/annotate_paint.cc +++ b/source/blender/editors/gpencil_legacy/annotate_paint.cc @@ -1463,7 +1463,7 @@ static tGPsdata *annotation_session_initpaint(bContext *C) tGPsdata *p = nullptr; /* create new context data */ - p = static_cast(MEM_callocN(sizeof(tGPsdata), "Annotation Drawing Data")); + p = MEM_new("Annotation Drawing Data"); /* Try to initialize context data * WARNING: This may not always succeed (e.g. using GP in an annotation-only context) @@ -1473,7 +1473,7 @@ static tGPsdata *annotation_session_initpaint(bContext *C) * NOTE: It should be safe to just free the data, since failing context checks should * only happen when no data has been allocated. */ - MEM_freeN(p); + MEM_delete(p); return nullptr; } @@ -1518,7 +1518,7 @@ static void annotation_session_free(tGPsdata *p) if (p->depths) { ED_view3d_depths_free(p->depths); } - MEM_freeN(p); + MEM_delete(p); } /* init new stroke */