LayerState::makeInstance to return unique_ptr
diff --git a/include/rive/animation/animation_state.hpp b/include/rive/animation/animation_state.hpp
index aff5c3d..5cb0282 100644
--- a/include/rive/animation/animation_state.hpp
+++ b/include/rive/animation/animation_state.hpp
@@ -15,7 +15,7 @@
public:
const LinearAnimation* animation() const { return m_Animation; }
- StateInstance* makeInstance(ArtboardInstance*) const override;
+ std::unique_ptr<StateInstance> makeInstance(ArtboardInstance*) const override;
};
} // namespace rive
diff --git a/include/rive/animation/blend_state_1d.hpp b/include/rive/animation/blend_state_1d.hpp
index 83d0695..e50c100 100644
--- a/include/rive/animation/blend_state_1d.hpp
+++ b/include/rive/animation/blend_state_1d.hpp
@@ -12,7 +12,7 @@
StatusCode import(ImportStack& importStack) override;
- StateInstance* makeInstance(ArtboardInstance*) const override;
+ std::unique_ptr<StateInstance> makeInstance(ArtboardInstance*) const override;
};
} // namespace rive
diff --git a/include/rive/animation/blend_state_direct.hpp b/include/rive/animation/blend_state_direct.hpp
index fd8f120..160f8de 100644
--- a/include/rive/animation/blend_state_direct.hpp
+++ b/include/rive/animation/blend_state_direct.hpp
@@ -5,7 +5,7 @@
namespace rive {
class BlendStateDirect : public BlendStateDirectBase {
public:
- StateInstance* makeInstance(ArtboardInstance*) const override;
+ std::unique_ptr<StateInstance> makeInstance(ArtboardInstance*) const override;
};
} // namespace rive
diff --git a/include/rive/animation/layer_state.hpp b/include/rive/animation/layer_state.hpp
index e957f9e..6e9b20b 100644
--- a/include/rive/animation/layer_state.hpp
+++ b/include/rive/animation/layer_state.hpp
@@ -36,7 +36,7 @@
/// Make an instance of this state that can be advanced and applied by
/// the state machine when it is active or being transitioned from.
- virtual StateInstance* makeInstance(ArtboardInstance* instance) const;
+ virtual std::unique_ptr<StateInstance> makeInstance(ArtboardInstance* instance) const;
};
} // namespace rive
diff --git a/src/animation/animation_state.cpp b/src/animation/animation_state.cpp
index c279289..3d25d42 100644
--- a/src/animation/animation_state.cpp
+++ b/src/animation/animation_state.cpp
@@ -7,10 +7,10 @@
using namespace rive;
-StateInstance* AnimationState::makeInstance(ArtboardInstance* instance) const {
+std::unique_ptr<StateInstance> AnimationState::makeInstance(ArtboardInstance* instance) const {
if (animation() == nullptr) {
// Failed to load at runtime/some new type we don't understand.
- return new SystemStateInstance(this, instance);
+ return std::make_unique<SystemStateInstance>(this, instance);
}
- return new AnimationStateInstance(this, instance);
+ return std::make_unique<AnimationStateInstance>(this, instance);
}
\ No newline at end of file
diff --git a/src/animation/blend_state_1d.cpp b/src/animation/blend_state_1d.cpp
index 3399c6e..0273fcb 100644
--- a/src/animation/blend_state_1d.cpp
+++ b/src/animation/blend_state_1d.cpp
@@ -6,8 +6,8 @@
using namespace rive;
-StateInstance* BlendState1D::makeInstance(ArtboardInstance* instance) const {
- return new BlendState1DInstance(this, instance);
+std::unique_ptr<StateInstance> BlendState1D::makeInstance(ArtboardInstance* instance) const {
+ return std::make_unique<BlendState1DInstance>(this, instance);
}
StatusCode BlendState1D::import(ImportStack& importStack) {
diff --git a/src/animation/blend_state_direct.cpp b/src/animation/blend_state_direct.cpp
index cc421ac..b90ff03 100644
--- a/src/animation/blend_state_direct.cpp
+++ b/src/animation/blend_state_direct.cpp
@@ -6,6 +6,6 @@
using namespace rive;
-StateInstance* BlendStateDirect::makeInstance(ArtboardInstance* instance) const {
- return new BlendStateDirectInstance(this, instance);
+std::unique_ptr<StateInstance> BlendStateDirect::makeInstance(ArtboardInstance* instance) const {
+ return std::make_unique<BlendStateDirectInstance>(this, instance);
}
\ No newline at end of file
diff --git a/src/animation/layer_state.cpp b/src/animation/layer_state.cpp
index 42327ac..45c0e8c 100644
--- a/src/animation/layer_state.cpp
+++ b/src/animation/layer_state.cpp
@@ -46,6 +46,6 @@
void LayerState::addTransition(StateTransition* transition) { m_Transitions.push_back(transition); }
-StateInstance* LayerState::makeInstance(ArtboardInstance* instance) const {
- return new SystemStateInstance(this, instance);
+std::unique_ptr<StateInstance> LayerState::makeInstance(ArtboardInstance* instance) const {
+ return std::make_unique<SystemStateInstance>(this, instance);
}
\ No newline at end of file
diff --git a/src/animation/state_machine_instance.cpp b/src/animation/state_machine_instance.cpp
index 1176c6c..b5bfa84 100644
--- a/src/animation/state_machine_instance.cpp
+++ b/src/animation/state_machine_instance.cpp
@@ -52,7 +52,7 @@
void init(const StateMachineLayer* layer, ArtboardInstance* instance) {
m_ArtboardInstance = instance;
assert(m_Layer == nullptr);
- m_AnyStateInstance = layer->anyState()->makeInstance(instance);
+ m_AnyStateInstance = layer->anyState()->makeInstance(instance).release();
m_Layer = layer;
changeState(m_Layer->entryState());
}
@@ -124,7 +124,7 @@
if ((m_CurrentState == nullptr ? nullptr : m_CurrentState->state()) == stateTo) {
return false;
}
- m_CurrentState = stateTo == nullptr ? nullptr : stateTo->makeInstance(m_ArtboardInstance);
+ m_CurrentState = stateTo == nullptr ? nullptr : stateTo->makeInstance(m_ArtboardInstance).release();
return true;
}