Skip to content

Commit 11e9c65

Browse files
susan101566susan101566
andcommitted
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 <[email protected]>
1 parent f87e58e commit 11e9c65

File tree

4 files changed

+11
-11
lines changed

4 files changed

+11
-11
lines changed

.rive_head

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
b03d365c93d0d52f0f05ae598deacbf7dd330a53
1+
90da85fbb4151a7a4a1c30cf2f6738929debe925

include/rive/container_component.hpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@ class ContainerComponent : public ContainerComponentBase
1313
virtual void addChild(Component* component);
1414
bool collapse(bool value) override;
1515

16-
// Returns true if it searched through all of its children. predicate can
17-
// return false to stop searching.
16+
// Returns whether predicate returns true for the current Component.
1817
bool forAll(std::function<bool(Component*)> predicate);
19-
bool forEachChild(std::function<bool(Component*)> predicate);
18+
19+
// Recursively descend onto all the children in the hierarchy tree.
20+
// If predicate returns false, it won't recurse down a particular branch.
21+
void forEachChild(std::function<bool(Component*)> predicate);
2022

2123
private:
2224
std::vector<Component*> m_children;

src/animation/state_machine_instance.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1220,7 +1220,7 @@ void StateMachineInstance::addToHitLookup(
12201220
hitLookup,
12211221
listenerGroup,
12221222
isOpaque);
1223-
return true;
1223+
return false;
12241224
});
12251225
return;
12261226
}

src/container_component.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,17 @@ bool ContainerComponent::forAll(std::function<bool(Component*)> predicate)
2929
return true;
3030
}
3131

32-
bool ContainerComponent::forEachChild(std::function<bool(Component*)> predicate)
32+
void ContainerComponent::forEachChild(std::function<bool(Component*)> predicate)
3333
{
3434
for (Component* child : m_children)
3535
{
3636
if (!predicate(child))
3737
{
38-
return false;
38+
continue;
3939
}
40-
if (child->is<ContainerComponent>() &&
41-
!child->as<ContainerComponent>()->forEachChild(predicate))
40+
if (child->is<ContainerComponent>())
4241
{
43-
return false;
42+
child->as<ContainerComponent>()->forEachChild(predicate);
4443
}
4544
}
46-
return true;
4745
}

0 commit comments

Comments
 (0)