pgraph: Fix nodes with same key but diff value getting flattened

This was a regression from 69b3468b2c40111def34e4b609a0aa36267c5582
This commit is contained in:
rdb 2022-01-05 08:01:56 +01:00
parent 28b566726a
commit d65ca1edd6
2 changed files with 52 additions and 1 deletions

View File

@ -1325,7 +1325,7 @@ compare_tags(const PandaNode *other) const {
return cmp;
}
cmp = strcmp(a_data.get_key(ai).c_str(), b_data.get_key(bi).c_str());
cmp = strcmp(a_data.get_data(ai).c_str(), b_data.get_data(bi).c_str());
if (cmp != 0) {
return cmp;
}

View File

@ -133,6 +133,57 @@ def test_weak_nodepath_comparison():
assert weak.node() == path.node()
def test_nodepath_flatten_tags_identical():
from panda3d.core import NodePath, PandaNode
# Do flatten nodes with same tags
node1 = PandaNode("node1")
node1.set_tag("key", "value")
node2 = PandaNode("node2")
node2.set_tag("key", "value")
path = NodePath("parent")
path.node().add_child(node1)
path.node().add_child(node2)
path.flatten_strong()
assert len(path.children) == 1
def test_nodepath_flatten_tags_same_key():
from panda3d.core import NodePath, PandaNode
# Don't flatten nodes with different tag keys
node1 = PandaNode("node1")
node1.set_tag("key1", "value")
node2 = PandaNode("node2")
node2.set_tag("key2", "value")
path = NodePath("parent")
path.node().add_child(node1)
path.node().add_child(node2)
path.flatten_strong()
assert len(path.children) == 2
def test_nodepath_flatten_tags_same_value():
from panda3d.core import NodePath, PandaNode
# Don't flatten nodes with different tag values
node1 = PandaNode("node1")
node1.set_tag("key", "value1")
node2 = PandaNode("node2")
node2.set_tag("key", "value2")
path = NodePath("parent")
path.node().add_child(node1)
path.node().add_child(node2)
path.flatten_strong()
assert len(path.children) == 2
def test_nodepath_python_tags():
from panda3d.core import NodePath