Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[sdf] Fix Sdf_Children<ChildPolicy>::Find to return correct value #3486

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions pxr/usd/sdf/children.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,19 +86,18 @@ size_t
Sdf_Children<ChildPolicy>::Find(const KeyType &key) const
{
if (!TF_VERIFY(IsValid())) {
return 0;
return _childNames.size();
}

_UpdateChildNames();

const FieldType expectedKey(_keyPolicy.Canonicalize(key));
size_t i = 0;
for (i=0; i < _childNames.size(); i++) {
for (size_t i=0; i < _childNames.size(); i++) {
if (_childNames[i] == expectedKey) {
break;
return i;
}
}
return i;
return _childNames.size();
}

template<class ChildPolicy>
Expand Down
25 changes: 25 additions & 0 deletions pxr/usd/sdf/testenv/testSdfPrim.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,31 @@ def test_NameChildrenInsert(self):
print(" previous list {0}".format(prevGroundTruthList))
self.fail("Prim insertion test failed")

def test_NameChildrenFind(self):
layer = Sdf.Layer.CreateAnonymous("test")
rootPrim = Sdf.PrimSpec(layer, 'Root', Sdf.SpecifierDef, 'Scope')

# find the index of a non-existent prim with no children
index = rootPrim.nameChildren.index('nonexistent')
self.assertEqual(index, -1)

# insert some child prims to find
for i in range(10):
primName = 'geom{0}'.format(i)
primSpec = Sdf.PrimSpec(layer, primName, Sdf.SpecifierDef, 'Scope')

rootPrim.nameChildren.insert(i, primSpec)

# find the index of the prims
for i in range(10):
primName = 'geom{0}'.format(i)
index = rootPrim.nameChildren.index(primName)
self.assertEqual(index, i)

# find the index of a non-existent prim
index = rootPrim.nameChildren.index('nonexistent')
self.assertEqual(index, -1)

def test_InertSpecRemoval(self):
layer = Sdf.Layer.CreateAnonymous()

Expand Down