Anim: make layered Action sub-data copy constructors explicit

Mark these copy constructors as 'explicit' in `blender::animrig`:

- `Slot`
- `StripKeyframeData`
- `ChannelBag`

The copy constructors for the other related classes were already
`explicit` or `deleted`.

This prevents bugs by disallowing implicit copies. For example:

```cpp
ChannelBag cbag = agrp->channel_bag->wrap();
```

This should have been a reference (`ChannelBag &cbag`), an easy mistake
which is now caught by the compiler (and fixed in this commit).

No functional changes. The implicit copy that was removed was just
inefficient, but didn't produce the wrong results.

Pull Request: https://projects.blender.org/blender/blender/pulls/128424
This commit is contained in:
Sybren A. Stüvel
2024-10-01 14:54:15 +02:00
parent 476fd1641c
commit 38f5b8d7d4
3 changed files with 5 additions and 5 deletions

View File

@@ -605,7 +605,7 @@ ENUM_OPERATORS(Layer::Flags, Layer::Flags::Enabled);
class Slot : public ::ActionSlot {
public:
Slot();
Slot(const Slot &other);
explicit Slot(const Slot &other);
~Slot();
/**
@@ -740,7 +740,7 @@ class StripKeyframeData : public ::ActionStripKeyframeData {
static constexpr Strip::Type TYPE = Strip::Type::Keyframe;
StripKeyframeData() = default;
StripKeyframeData(const StripKeyframeData &other);
explicit StripKeyframeData(const StripKeyframeData &other);
~StripKeyframeData();
/* ChannelBag array access. */
@@ -806,7 +806,7 @@ static_assert(sizeof(StripKeyframeData) == sizeof(::ActionStripKeyframeData),
class ChannelBag : public ::ActionChannelBag {
public:
ChannelBag() = default;
ChannelBag(const ChannelBag &other);
explicit ChannelBag(const ChannelBag &other);
~ChannelBag();
/* FCurves access. */

View File

@@ -892,7 +892,7 @@ TEST_F(ActionLayersTest, conversion_to_layered)
ASSERT_TRUE(converted != action);
EXPECT_STREQ(converted->id.name, "ACACÄnimåtië_layered");
Strip *strip = converted->layer(0)->strip(0);
StripKeyframeData strip_data = strip->data<StripKeyframeData>(*converted);
StripKeyframeData &strip_data = strip->data<StripKeyframeData>(*converted);
ChannelBag *bag = strip_data.channelbag(0);
ASSERT_EQ(bag->fcurve_array_num, 2);
ASSERT_EQ(bag->fcurve_array[0]->totvert, 2);

View File

@@ -1212,7 +1212,7 @@ void action_group_to_keylist(AnimData *adt,
}
/* Layered actions. */
animrig::ChannelBag channel_bag = agrp->channel_bag->wrap();
animrig::ChannelBag &channel_bag = agrp->channel_bag->wrap();
Span<FCurve *> fcurves = channel_bag.fcurves().slice(agrp->fcurve_range_start,
agrp->fcurve_range_length);
for (FCurve *fcurve : fcurves) {