Skip to content

Commit 7a72518

Browse files
ktrongnhanminggo
authored andcommitted
Fixing a bug in Node::enumerateChildren (#20045)
This patch fixes an issue that if both // (recursive enumeration) and .. (starting from parent node) are specified, Node::enumerateChildren does not honor the latter and starts searching from current node rather than parent node.
1 parent 67ba5b4 commit 7a72518

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

cocos/2d/CCNode.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -865,7 +865,7 @@ void Node::enumerateChildren(const std::string &name, const std::function<bool (
865865
if (searchRecursively)
866866
{
867867
// name is '//xxx'
868-
target->doEnumerateRecursive(this, newName, callback);
868+
target->doEnumerateRecursive(target, newName, callback);
869869
}
870870
else
871871
{

tests/cpp-tests/Classes/NodeTest/NodeTest.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1384,14 +1384,14 @@ void NodeNameTest::test(float dt)
13841384
// search from parent
13851385
// name is xxx/..
13861386
i = 0;
1387-
parent->enumerateChildren("node/..", [&i](Node* node) -> bool {
1387+
parent->getChildByName("node1")->enumerateChildren("node[[:digit:]]+/node/..", [&i](Node* node) -> bool {
13881388
++i;
13891389
return true;
13901390
});
13911391
CCAssert(i == 1, "");
13921392

13931393
i = 0;
1394-
parent->enumerateChildren("node/..", [&i](Node* node) -> bool {
1394+
parent->getChildByName("node1")->enumerateChildren("node[[:digit:]]+/node/..", [&i](Node* node) -> bool {
13951395
++i;
13961396
return false;
13971397
});
@@ -1430,11 +1430,11 @@ void NodeNameTest::test(float dt)
14301430
CCAssert(i == 1, "");
14311431

14321432
i = 0;
1433-
parent->enumerateChildren("//node[[:digit:]]+/..", [&i](Node* node) -> bool {
1433+
parent->getChildByName("node1")->enumerateChildren("//node[[:digit:]]+/..", [&i](Node* node) -> bool {
14341434
++i;
14351435
return false;
14361436
});
1437-
CCAssert(i == 100, "");
1437+
CCAssert(i == 110, "");
14381438

14391439
// utils::findChildren()
14401440

0 commit comments

Comments
 (0)