Skip to content

Commit

Permalink
Nnnn duplicate state layers
Browse files Browse the repository at this point in the history
adding support for duplicating state machine layers with view model conditions.
It also handles missing view model conditions in the cpp runtime when they are not fully set
and changes how the default values are retrieved to avoid memory leaks

Diffs=
8f9da9d694 Nnnn duplicate state layers (#9067)

Co-authored-by: hernan <[email protected]>
  • Loading branch information
bodymovin and bodymovin committed Feb 19, 2025
1 parent 406a997 commit 4a63768
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .rive_head
Original file line number Diff line number Diff line change
@@ -1 +1 @@
63642c62d46f41939545609dd151b68d0f4f67fe
8f9da9d694556c39397c96dbd24dde118220f0ed
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,17 @@ class TransitionPropertyViewModelComparator
template <typename T = BindableProperty, typename U>
U value(const StateMachineInstance* stateMachineInstance)
{
if (m_bindableProperty->is<T>())
if (m_bindableProperty != nullptr && m_bindableProperty->is<T>())
{
auto bindableInstance =
stateMachineInstance->bindablePropertyInstance(
m_bindableProperty);
return bindableInstance->as<T>()->propertyValue();
if (bindableInstance != nullptr)
{
return bindableInstance->as<T>()->propertyValue();
}
}
return (new T())->propertyValue();
return T::defaultValue;
};
void useInLayer(const StateMachineInstance* stateMachineInstance,
StateMachineLayerInstance* layerInstance) const override;
Expand Down
1 change: 1 addition & 0 deletions include/rive/data_bind/bindable_property_boolean.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ namespace rive
class BindablePropertyBoolean : public BindablePropertyBooleanBase
{
public:
constexpr static bool defaultValue = false;
};
} // namespace rive

Expand Down
1 change: 1 addition & 0 deletions include/rive/data_bind/bindable_property_color.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ namespace rive
class BindablePropertyColor : public BindablePropertyColorBase
{
public:
constexpr static int defaultValue = 0;
};
} // namespace rive

Expand Down
1 change: 1 addition & 0 deletions include/rive/data_bind/bindable_property_enum.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ namespace rive
class BindablePropertyEnum : public BindablePropertyEnumBase
{
public:
constexpr static uint16_t defaultValue = 0;
};
} // namespace rive

Expand Down
1 change: 1 addition & 0 deletions include/rive/data_bind/bindable_property_number.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ namespace rive
class BindablePropertyNumber : public BindablePropertyNumberBase
{
public:
constexpr static float defaultValue = 0;
};
} // namespace rive

Expand Down
2 changes: 2 additions & 0 deletions include/rive/data_bind/bindable_property_string.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
#define _RIVE_BINDABLE_PROPERTY_STRING_HPP_
#include "rive/generated/data_bind/bindable_property_string_base.hpp"
#include <stdio.h>
#include <string_view>
namespace rive
{
class BindablePropertyString : public BindablePropertyStringBase
{
public:
static constexpr const char* defaultValue = "";
};
} // namespace rive

Expand Down
1 change: 1 addition & 0 deletions include/rive/data_bind/bindable_property_trigger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ namespace rive
class BindablePropertyTrigger : public BindablePropertyTriggerBase
{
public:
constexpr static uint32_t defaultValue = 0;
};
} // namespace rive

Expand Down
4 changes: 4 additions & 0 deletions src/animation/transition_property_viewmodel_comparator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,10 @@ void TransitionPropertyViewModelComparator::useInLayer(

auto bindableInstance =
stateMachineInstance->bindablePropertyInstance(m_bindableProperty);
if (bindableInstance == nullptr)
{
return;
}
auto dataBind =
stateMachineInstance->bindableDataBindToTarget(bindableInstance);
auto source = dataBind->source();
Expand Down

0 comments on commit 4a63768

Please sign in to comment.