Skip to content

Commit

Permalink
Do not load files with invalid paint mutators.
Browse files Browse the repository at this point in the history
Fails importing files with multiple paint mutators per paint. This is invalid and the editor does clean this up. We also print a helpful message in debug mode so you can know why the file failed to load.

Details here: https://2dimensions.slack.com/archives/CLLCU09T6/p1729178961824429

Diffs=
96d45f6824 Do not load files with invalid paint mutators. (#8366)

Co-authored-by: Luigi Rosso <luigi-rosso@users.noreply.github.com>
  • Loading branch information
luigi-rosso and luigi-rosso committed Oct 22, 2024
1 parent bf71e24 commit ac8285c
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .rive_head
Original file line number Diff line number Diff line change
@@ -1 +1 @@
76f79a22e26bcc672840e3ba601cb84eb938aecb
96d45f68240ef35a38c91eeec654ed771a006458
6 changes: 6 additions & 0 deletions include/rive/core.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
#include "rive/core/binary_reader.hpp"
#include "rive/status_code.hpp"

#ifdef DEBUG
#define DEBUG_PRINT(msg) fprintf(stderr, msg "\n");
#else
#define DEBUG_PRINT(msg)
#endif

namespace rive
{
class CoreContext;
Expand Down
4 changes: 3 additions & 1 deletion include/rive/shapes/paint/shape_paint_mutator.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#ifndef _RIVE_SHAPE_PAINT_MUTATOR_HPP_
#define _RIVE_SHAPE_PAINT_MUTATOR_HPP_

#include "rive/status_code.hpp"

namespace rive
{
class Component;
Expand All @@ -16,7 +18,7 @@ class ShapePaintMutator
protected:
/// Hook up this paint mutator as the mutator for the shape paint
/// expected to be the parent.
bool initPaintMutator(Component* component);
StatusCode initPaintMutator(Component* component);
virtual void renderOpacityChanged() = 0;

RenderPaint* renderPaint() const { return m_RenderPaint; }
Expand Down
6 changes: 1 addition & 5 deletions src/shapes/paint/linear_gradient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,7 @@ StatusCode LinearGradient::onAddedDirty(CoreContext* context)
return code;
}

if (!initPaintMutator(this))
{
return StatusCode::MissingObject;
}
return StatusCode::Ok;
return initPaintMutator(this);
}

void LinearGradient::buildDependencies()
Expand Down
15 changes: 11 additions & 4 deletions src/shapes/paint/shape_paint_mutator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,27 @@

using namespace rive;

bool ShapePaintMutator::initPaintMutator(Component* component)
StatusCode ShapePaintMutator::initPaintMutator(Component* component)
{
auto parent = component->parent();
m_Component = component;
if (parent->is<ShapePaint>())
{
if (parent->as<ShapePaint>()->renderPaint() != nullptr)
{
DEBUG_PRINT(
"ShapePaintMutator::initPaintMutator - ShapePaint has already "
"been asigned a mutator. Does this file have multiple solid "
"color/gradients in one single fill/stroke?");
return StatusCode::InvalidObject;
}
// Set this object as the mutator for the shape paint and get a
// reference to the paint we'll be mutating.
m_RenderPaint = parent->as<ShapePaint>()->initRenderPaint(this);
return true;
return StatusCode::Ok;
}
return false;
return StatusCode::MissingObject;
}

void ShapePaintMutator::renderOpacity(float value)
{
if (m_RenderOpacity == value)
Expand Down
8 changes: 4 additions & 4 deletions src/shapes/paint/solid_color.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ StatusCode SolidColor::onAddedDirty(CoreContext* context)
{
return code;
}
if (!initPaintMutator(this))
if ((code = initPaintMutator(this)) == StatusCode::Ok)
{
return StatusCode::MissingObject;
renderOpacityChanged();
}
renderOpacityChanged();
return StatusCode::Ok;

return code;
}

void SolidColor::renderOpacityChanged()
Expand Down

0 comments on commit ac8285c

Please sign in to comment.