[Bf-blender-cvs] [5e6c7de3e91] master: Animation: enforce that the active keyframe is always selected

Sybren A. Stüvel noreply at git.blender.org
Mon Oct 12 17:00:23 CEST 2020


Commit: 5e6c7de3e918f7ecbf4ea898f6e5b8a2373ad17e
Author: Sybren A. Stüvel
Date:   Mon Oct 12 16:55:46 2020 +0200
Branches: master
https://developer.blender.org/rB5e6c7de3e918f7ecbf4ea898f6e5b8a2373ad17e

Animation: enforce that the active keyframe is always selected

Check selection state in `BKE_fcurve_active_keyframe_index()`, and only
return the active keyframe index when that keyframe is actually selected.
This is now also asserted in the `BKE_fcurve_active_keyframe_set()` function,
which is now also used when inserting a keyframe.

===================================================================

M	source/blender/blenkernel/intern/fcurve.c
M	source/blender/editors/animation/keyframing.c
M	source/blender/makesdna/DNA_anim_types.h

===================================================================

diff --git a/source/blender/blenkernel/intern/fcurve.c b/source/blender/blenkernel/intern/fcurve.c
index d2a9064a373..d57ef45107c 100644
--- a/source/blender/blenkernel/intern/fcurve.c
+++ b/source/blender/blenkernel/intern/fcurve.c
@@ -839,6 +839,8 @@ bool BKE_fcurve_calc_range(
  */
 void BKE_fcurve_active_keyframe_set(FCurve *fcu, const BezTriple *active_bezt)
 {
+  /* The active keyframe should always be selected. */
+  BLI_assert(active_bezt->f2 & SELECT);
   fcu->active_keyframe_index = (active_bezt == NULL) ? FCURVE_ACTIVE_KEYFRAME_NONE :
                                                        active_bezt - fcu->bezt;
 }
@@ -850,12 +852,18 @@ int BKE_fcurve_active_keyframe_index(const FCurve *fcu)
 {
   const int active_keyframe_index = fcu->active_keyframe_index;
 
-  /* Sanity checks. */
+  /* Array access boundary checks. */
   if ((fcu->bezt == NULL) || (active_keyframe_index >= fcu->totvert) ||
       (active_keyframe_index < 0)) {
     return FCURVE_ACTIVE_KEYFRAME_NONE;
   }
 
+  const BezTriple *active_bezt = &fcu->bezt[active_keyframe_index];
+  if ((active_bezt->f2 & SELECT) == 0) {
+    /* The active keyframe should always be selected. If it's not selected, it can't be active. */
+    return FCURVE_ACTIVE_KEYFRAME_NONE;
+  }
+
   return active_keyframe_index;
 }
 
diff --git a/source/blender/editors/animation/keyframing.c b/source/blender/editors/animation/keyframing.c
index c2a772604f2..967ca13c17d 100644
--- a/source/blender/editors/animation/keyframing.c
+++ b/source/blender/editors/animation/keyframing.c
@@ -605,8 +605,7 @@ int insert_vert_fcurve(
 
   /* add temp beztriple to keyframes */
   a = insert_bezt_fcurve(fcu, &beztr, flag);
-
-  fcu->active_keyframe_index = a;
+  BKE_fcurve_active_keyframe_set(fcu, &fcu->bezt[a]);
 
   /* what if 'a' is a negative index?
    * for now, just exit to prevent any segfaults
diff --git a/source/blender/makesdna/DNA_anim_types.h b/source/blender/makesdna/DNA_anim_types.h
index f17d8b84790..1a74166da31 100644
--- a/source/blender/makesdna/DNA_anim_types.h
+++ b/source/blender/makesdna/DNA_anim_types.h
@@ -593,6 +593,9 @@ typedef struct FCurve {
   /**
    * Index of active keyframe in #bezt for numerical editing in the interface. A value of
    * #FCURVE_ACTIVE_KEYFRAME_NONE indicates that the FCurve has no active keyframe.
+   *
+   * Do not access directly, use #BKE_fcurve_active_keyframe_index() and
+   * #BKE_fcurve_active_keyframe_set() instead.
    */
   int active_keyframe_index;



More information about the Bf-blender-cvs mailing list