Removed single-threaded counter. This counter type is single-threaded and makes all objects using it thread-unsafe. Diffs= 6a74a01f2 Removed single-threaded counter. (#6090) Co-authored-by: Dragoș Tiselice <dragos@rive.app>
diff --git a/.rive_head b/.rive_head index 0c71633..3bd9e52 100644 --- a/.rive_head +++ b/.rive_head
@@ -1 +1 @@ -b4ef09a6d619423eb7a4b96d34d4acfd62dbc527 +6a74a01f27fbdabe03827a72614e24f8eff018a0
diff --git a/include/rive/rive_counter.hpp b/include/rive/rive_counter.hpp deleted file mode 100644 index a378924..0000000 --- a/include/rive/rive_counter.hpp +++ /dev/null
@@ -1,44 +0,0 @@ -/* - * Copyright 2022 Rive - */ - -#ifndef _RIVE_COUNTER_HPP_ -#define _RIVE_COUNTER_HPP_ - -#include "rive/rive_types.hpp" - -namespace rive -{ - -struct Counter -{ - enum Type - { - kFile, - kArtboardInstance, - kLinearAnimationInstance, - kStateMachineInstance, - - kBuffer, - kPath, - kPaint, - kShader, - kImage, - - kLastType = kImage, - }; - - static constexpr int kNumTypes = Type::kLastType + 1; - static int counts[kNumTypes]; - - static void update(Type ct, int delta) - { - assert(delta == 1 || delta == -1); - counts[ct] += delta; - assert(counts[ct] >= 0); - } -}; - -} // namespace rive - -#endif
diff --git a/src/animation/linear_animation_instance.cpp b/src/animation/linear_animation_instance.cpp index b6232d1..3c31b72 100644 --- a/src/animation/linear_animation_instance.cpp +++ b/src/animation/linear_animation_instance.cpp
@@ -2,7 +2,6 @@ #include "rive/animation/linear_animation.hpp" #include "rive/animation/loop.hpp" #include "rive/animation/keyed_callback_reporter.hpp" -#include "rive/rive_counter.hpp" #include <cmath> #include <cassert> @@ -18,9 +17,7 @@ m_lastTotalTime(0.0f), m_spilledTime(0.0f), m_direction(1) -{ - Counter::update(Counter::kLinearAnimationInstance, +1); -} +{} LinearAnimationInstance::LinearAnimationInstance(LinearAnimationInstance const& lhs) : Scene(lhs), @@ -32,14 +29,9 @@ m_direction(lhs.m_direction), m_didLoop(lhs.m_didLoop), m_loopValue(lhs.m_loopValue) -{ - Counter::update(Counter::kLinearAnimationInstance, +1); -} +{} -LinearAnimationInstance::~LinearAnimationInstance() -{ - Counter::update(Counter::kLinearAnimationInstance, -1); -} +LinearAnimationInstance::~LinearAnimationInstance() {} bool LinearAnimationInstance::advanceAndApply(float seconds) {
diff --git a/src/animation/state_machine_instance.cpp b/src/animation/state_machine_instance.cpp index eeb9562..55dee4d 100644 --- a/src/animation/state_machine_instance.cpp +++ b/src/animation/state_machine_instance.cpp
@@ -21,7 +21,6 @@ #include "rive/math/hit_test.hpp" #include "rive/nested_animation.hpp" #include "rive/nested_artboard.hpp" -#include "rive/rive_counter.hpp" #include "rive/shapes/shape.hpp" #include "rive/core/field_types/core_callback_type.hpp" #include "rive/generated/core_registry.hpp" @@ -433,8 +432,6 @@ ArtboardInstance* instance) : Scene(instance), m_machine(machine) { - Counter::update(Counter::kStateMachineInstance, +1); - const auto count = machine->inputCount(); m_inputInstances.resize(count); for (size_t i = 0; i < count; i++) @@ -533,8 +530,6 @@ delete inst; } delete[] m_layers; - - Counter::update(Counter::kStateMachineInstance, -1); } bool StateMachineInstance::advance(float seconds) @@ -691,7 +686,8 @@ CoreRegistry::setCallback(coreObject, propertyKey, data); } -void StateMachineInstance::notifyEventListeners(std::vector<EventReport> events, NestedArtboard* source) +void StateMachineInstance::notifyEventListeners(std::vector<EventReport> events, + NestedArtboard* source) { if (events.size() > 0) { @@ -700,8 +696,7 @@ { auto listener = m_machine->listener(i); auto target = artboard()->resolve(listener->targetId()); - if (listener != nullptr && - listener->listenerType() == ListenerType::event && + if (listener != nullptr && listener->listenerType() == ListenerType::event && (source == nullptr || source == target)) { for (const auto event : events) @@ -722,4 +717,4 @@ m_parentStateMachineInstance->notifyEventListeners(events, m_parentNestedArtboard); } } -} \ No newline at end of file +}
diff --git a/src/artboard.cpp b/src/artboard.cpp index 457143b..86dcfd7 100644 --- a/src/artboard.cpp +++ b/src/artboard.cpp
@@ -806,13 +806,12 @@ ////////// ArtboardInstance -#include "rive/rive_counter.hpp" #include "rive/animation/linear_animation_instance.hpp" #include "rive/animation/state_machine_instance.hpp" -ArtboardInstance::ArtboardInstance() { Counter::update(Counter::kArtboardInstance, +1); } +ArtboardInstance::ArtboardInstance() {} -ArtboardInstance::~ArtboardInstance() { Counter::update(Counter::kArtboardInstance, -1); } +ArtboardInstance::~ArtboardInstance() {} std::unique_ptr<LinearAnimationInstance> ArtboardInstance::animationAt(size_t index) {
diff --git a/src/file.cpp b/src/file.cpp index 952dc0e..cf77acb 100644 --- a/src/file.cpp +++ b/src/file.cpp
@@ -1,5 +1,4 @@ #include "rive/file.hpp" -#include "rive/rive_counter.hpp" #include "rive/runtime_header.hpp" #include "rive/animation/animation.hpp" #include "rive/core/field_types/core_color_type.hpp" @@ -124,12 +123,10 @@ File::File(Factory* factory, FileAssetLoader* assetLoader) : m_Factory(factory), m_AssetLoader(assetLoader) { - Counter::update(Counter::kFile, +1); - assert(factory); } -File::~File() { Counter::update(Counter::kFile, -1); } +File::~File() {} std::unique_ptr<File> File::import(Span<const uint8_t> bytes, Factory* factory, @@ -425,4 +422,4 @@ } return strippedData; } -#endif \ No newline at end of file +#endif
diff --git a/src/renderer.cpp b/src/renderer.cpp index 3941fe7..0d34b8c 100644 --- a/src/renderer.cpp +++ b/src/renderer.cpp
@@ -1,6 +1,5 @@ #include "rive/math/mat2d.hpp" #include "rive/renderer.hpp" -#include "rive/rive_counter.hpp" #include "rive/text_engine.hpp" using namespace rive; @@ -82,11 +81,9 @@ RenderBuffer::RenderBuffer(RenderBufferType type, RenderBufferFlags flags, size_t sizeInBytes) : m_type(type), m_flags(flags), m_sizeInBytes(sizeInBytes) -{ - Counter::update(Counter::kBuffer, 1); -} +{} -RenderBuffer::~RenderBuffer() { Counter::update(Counter::kBuffer, -1); } +RenderBuffer::~RenderBuffer() {} void* RenderBuffer::map() { @@ -103,21 +100,18 @@ onUnmap(); } -RenderShader::RenderShader() { Counter::update(Counter::kShader, 1); } -RenderShader::~RenderShader() { Counter::update(Counter::kShader, -1); } +RenderShader::RenderShader() {} +RenderShader::~RenderShader() {} -RenderPaint::RenderPaint() { Counter::update(Counter::kPaint, 1); } -RenderPaint::~RenderPaint() { Counter::update(Counter::kPaint, -1); } +RenderPaint::RenderPaint() {} +RenderPaint::~RenderPaint() {} -RenderImage::RenderImage(const Mat2D& uvTransform) : m_uvTransform(uvTransform) -{ - Counter::update(Counter::kImage, 1); -} -RenderImage::RenderImage() { Counter::update(Counter::kImage, 1); } -RenderImage::~RenderImage() { Counter::update(Counter::kImage, -1); } +RenderImage::RenderImage(const Mat2D& uvTransform) : m_uvTransform(uvTransform) {} +RenderImage::RenderImage() {} +RenderImage::~RenderImage() {} -RenderPath::RenderPath() { Counter::update(Counter::kPath, 1); } -RenderPath::~RenderPath() { Counter::update(Counter::kPath, -1); } +RenderPath::RenderPath() {} +RenderPath::~RenderPath() {} bool rive::isWhiteSpace(Unichar c) { return c <= ' ' || c == 0x2028; }
diff --git a/src/rive_counter.cpp b/src/rive_counter.cpp deleted file mode 100644 index fc33ffa..0000000 --- a/src/rive_counter.cpp +++ /dev/null
@@ -1,9 +0,0 @@ -/* - * Copyright 2022 Rive - */ - -#include "rive/rive_counter.hpp" - -using namespace rive; - -int Counter::counts[Type::kLastType + 1] = {};
diff --git a/test/file_test.cpp b/test/file_test.cpp index b60e5b5..504014c 100644 --- a/test/file_test.cpp +++ b/test/file_test.cpp
@@ -29,7 +29,6 @@ TEST_CASE("file can be read", "[file]") { - RenderObjectLeakChecker checker; auto file = ReadRiveFile("../../test/assets/two_artboards.riv"); // Default artboard should be named Two. @@ -41,7 +40,6 @@ TEST_CASE("file with animation can be read", "[file]") { - RenderObjectLeakChecker checker; auto file = ReadRiveFile("../../test/assets/juice.riv"); auto artboard = file->artboard(); @@ -67,7 +65,6 @@ TEST_CASE("artboards can be counted and accessed via index or name", "[file]") { - RenderObjectLeakChecker checker; auto file = ReadRiveFile("../../test/assets/dependency_test.riv"); // The artboards caqn be counted @@ -82,7 +79,6 @@ TEST_CASE("dependencies are as expected", "[file]") { - RenderObjectLeakChecker checker; // ┌────┐ // │Blue│ // └────┘ @@ -141,7 +137,6 @@ TEST_CASE("long name in object is parsed correctly", "[file]") { - RenderObjectLeakChecker checker; auto file = ReadRiveFile("../../test/assets/long_name.riv"); auto artboard = file->artboard(); @@ -151,7 +146,6 @@ TEST_CASE("file with in-band images can have the stripped", "[file]") { - RenderObjectLeakChecker checker; FILE* fp = fopen("../../test/assets/jellyfish_test.riv", "rb"); REQUIRE(fp != nullptr);
diff --git a/test/image_asset_test.cpp b/test/image_asset_test.cpp index d6b4c80..a05b526 100644 --- a/test/image_asset_test.cpp +++ b/test/image_asset_test.cpp
@@ -13,7 +13,6 @@ TEST_CASE("image assets loads correctly", "[assets]") { - RenderObjectLeakChecker checker; auto file = ReadRiveFile("../../test/assets/walle.riv"); auto node = file->artboard()->find("walle"); @@ -45,7 +44,6 @@ TEST_CASE("out of band image assets loads correctly", "[assets]") { - RenderObjectLeakChecker checker; rive::NoOpFactory gEmptyFactory; std::string filename = "../../test/assets/out_of_band/walle.riv";
diff --git a/test/rive_file_reader.hpp b/test/rive_file_reader.hpp index 761b198..6ba4c94 100644 --- a/test/rive_file_reader.hpp +++ b/test/rive_file_reader.hpp
@@ -2,7 +2,6 @@ #define _RIVE_FILE_READER_HPP_ #include <rive/file.hpp> -#include "rive/rive_counter.hpp" #include "rive_testing.hpp" #include "utils/no_op_factory.hpp" @@ -38,29 +37,4 @@ return file; } -class RenderObjectLeakChecker -{ - int m_before[rive::Counter::kNumTypes]; - -public: - RenderObjectLeakChecker() - { - std::copy(rive::Counter::counts, - rive::Counter::counts + rive::Counter::kNumTypes, - m_before); - } - ~RenderObjectLeakChecker() - { - const int* after = rive::Counter::counts; - for (int i = 0; i < rive::Counter::kNumTypes; ++i) - { - if (rive::Counter::counts[i] != m_before[i]) - { - printf("[%d] before:%d after:%d\n", i, m_before[i], after[i]); - REQUIRE(false); - } - } - } -}; - #endif
diff --git a/viewer/src/viewer_content/viewer_content.cpp b/viewer/src/viewer_content/viewer_content.cpp index a8ba142..354f6f8 100644 --- a/viewer/src/viewer_content/viewer_content.cpp +++ b/viewer/src/viewer_content/viewer_content.cpp
@@ -3,7 +3,6 @@ */ #include "viewer/viewer_content.hpp" -#include "rive/rive_counter.hpp" #include <vector> ViewerContent::~ViewerContent() { DumpCounters("After deleting content"); }