diff --git a/source/blender/editors/gizmo_library/gizmo_types/snap3d_gizmo.c b/source/blender/editors/gizmo_library/gizmo_types/snap3d_gizmo.c index cccc3243640..2e1a8337a65 100644 --- a/source/blender/editors/gizmo_library/gizmo_types/snap3d_gizmo.c +++ b/source/blender/editors/gizmo_library/gizmo_types/snap3d_gizmo.c @@ -270,7 +270,10 @@ static void snap_gizmo_draw(const bContext *UNUSED(C), wmGizmo *gz) if (snap_gizmo->snap_state == NULL) { snap_cursor_init(snap_gizmo); } - /* All drawing is handled at the paint cursor. */ + + /* All drawing is handled at the paint cursor. + * Therefore, make sure that the #V3DSnapCursorState is the one of the gizmo being drawn. */ + ED_view3d_cursor_snap_state_set(snap_gizmo->snap_state); } static int snap_gizmo_test_select(bContext *C, wmGizmo *gz, const int mval[2]) diff --git a/source/blender/editors/include/ED_view3d.h b/source/blender/editors/include/ED_view3d.h index a7ab9b8d471..3fb49f6358c 100644 --- a/source/blender/editors/include/ED_view3d.h +++ b/source/blender/editors/include/ED_view3d.h @@ -337,6 +337,7 @@ typedef struct V3DSnapCursorState { void ED_view3d_cursor_snap_state_default_set(V3DSnapCursorState *state); V3DSnapCursorState *ED_view3d_cursor_snap_state_get(void); +void ED_view3d_cursor_snap_state_set(V3DSnapCursorState *state); V3DSnapCursorState *ED_view3d_cursor_snap_active(void); void ED_view3d_cursor_snap_deactive(V3DSnapCursorState *state); void ED_view3d_cursor_snap_prevpoint_set(V3DSnapCursorState *state, const float prev_point[3]); diff --git a/source/blender/editors/space_view3d/view3d_cursor_snap.c b/source/blender/editors/space_view3d/view3d_cursor_snap.c index 141222c746c..f405d3cd604 100644 --- a/source/blender/editors/space_view3d/view3d_cursor_snap.c +++ b/source/blender/editors/space_view3d/view3d_cursor_snap.c @@ -911,6 +911,26 @@ V3DSnapCursorState *ED_view3d_cursor_snap_state_get(void) return &((SnapStateIntern *)data_intern->state_intern.last)->snap_state; } +void ED_view3d_cursor_snap_state_set(V3DSnapCursorState *state) +{ + if (state == &g_data_intern.state_default) { + BLI_assert_unreachable(); + return; + } + + SnapStateIntern *state_intern = STATE_INTERN_GET(state); + if (state_intern == (SnapStateIntern *)g_data_intern.state_intern.last) { + return; + } + + if (!BLI_remlink_safe(&g_data_intern.state_intern, state_intern)) { + BLI_assert_unreachable(); + return; + } + + BLI_addtail(&g_data_intern.state_intern, state_intern); +} + static void v3d_cursor_snap_activate(void) { SnapCursorDataIntern *data_intern = &g_data_intern;