From 11e9c65e7a4fdf47a94e8d8d3366a1c02b087087 Mon Sep 17 00:00:00 2001 From: susan101566 Date: Wed, 22 Jan 2025 23:06:10 +0000 Subject: [PATCH] editor+runtime: fix slow hit-testing turns out forEachChild + recursion is a bad combo. Recurse on just the first level of the hierarchy. I also made sure that the `forEachChild` in both Dart and C++ would do the same thing, and have the same signature. Diffs= 90da85fbb4 editor+runtime: fix slow hit-testing (#8907) Co-authored-by: Susan Wang --- .rive_head | 2 +- include/rive/container_component.hpp | 8 +++++--- src/animation/state_machine_instance.cpp | 2 +- src/container_component.cpp | 10 ++++------ 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/.rive_head b/.rive_head index fb10e0bc..6dd81aad 100644 --- a/.rive_head +++ b/.rive_head @@ -1 +1 @@ -b03d365c93d0d52f0f05ae598deacbf7dd330a53 +90da85fbb4151a7a4a1c30cf2f6738929debe925 diff --git a/include/rive/container_component.hpp b/include/rive/container_component.hpp index 04cf246a..7fd590eb 100644 --- a/include/rive/container_component.hpp +++ b/include/rive/container_component.hpp @@ -13,10 +13,12 @@ class ContainerComponent : public ContainerComponentBase virtual void addChild(Component* component); bool collapse(bool value) override; - // Returns true if it searched through all of its children. predicate can - // return false to stop searching. + // Returns whether predicate returns true for the current Component. bool forAll(std::function predicate); - bool forEachChild(std::function predicate); + + // Recursively descend onto all the children in the hierarchy tree. + // If predicate returns false, it won't recurse down a particular branch. + void forEachChild(std::function predicate); private: std::vector m_children; diff --git a/src/animation/state_machine_instance.cpp b/src/animation/state_machine_instance.cpp index 6149b928..8d02ee34 100644 --- a/src/animation/state_machine_instance.cpp +++ b/src/animation/state_machine_instance.cpp @@ -1220,7 +1220,7 @@ void StateMachineInstance::addToHitLookup( hitLookup, listenerGroup, isOpaque); - return true; + return false; }); return; } diff --git a/src/container_component.cpp b/src/container_component.cpp index a018b2e2..4808c362 100644 --- a/src/container_component.cpp +++ b/src/container_component.cpp @@ -29,19 +29,17 @@ bool ContainerComponent::forAll(std::function predicate) return true; } -bool ContainerComponent::forEachChild(std::function predicate) +void ContainerComponent::forEachChild(std::function predicate) { for (Component* child : m_children) { if (!predicate(child)) { - return false; + continue; } - if (child->is() && - !child->as()->forEachChild(predicate)) + if (child->is()) { - return false; + child->as()->forEachChild(predicate); } } - return true; } \ No newline at end of file