OpenUSD icon indicating copy to clipboard operation
OpenUSD copied to clipboard

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

Open nvidia-jomiller opened this issue 11 months ago • 6 comments

In most cases, Sdf_Children<ChildPolicy>::Find would return the incorrect value of 0 instead the size of _childNames. This would incorrectly index into the first element when a match was not found

Description of Change(s)

Link to proposal (if applicable)

Fixes Issue(s)

Checklist

[x] I have created this PR based on the dev branch

[x] I have followed the coding conventions

[x] I have added unit tests that exercise this functionality (Reference: testing guidelines)

[x] I have verified that all unit tests pass with the proposed changes

[x] I have submitted a signed Contributor License Agreement (Reference: Contributor License Agreement instructions)

nvidia-jomiller avatar Jan 17 '25 22:01 nvidia-jomiller

Filed as internal issue #USD-10583

(This is an automated message. See here for more information.)

jesschimein avatar Jan 21 '25 17:01 jesschimein

/AzurePipelines run

jesschimein avatar Jan 21 '25 17:01 jesschimein

Azure Pipelines successfully started running 1 pipeline(s).

azure-pipelines[bot] avatar Jan 21 '25 17:01 azure-pipelines[bot]

Hey @nvidia-jomiller,

I'm not quite seeing the bug you mentioned in your PR description. Prior to your change, in the case where the given key isn't found, the index i would have been incremented to _childNames.size() and then returned. The test case you added worked both with and without your change. AFAICT, the only functional change is that in the failed verify case we now return _childNames.size() instead of 0.

Am I missing something?

sunyab avatar Feb 07 '25 23:02 sunyab

Hey @sunyab , thanks for taking a look!

The change was mostly facilitated by another task but yeah, now that I read through it line by line I see functionally it's equivalent. What I was mostly going from is checks in SdfChildrenView and code docs in Sdf_Children. I didn't see any tests specifically testing it so I modified and added a test. I think this might just be a readability thing where I was expecting to see _childNames.size() returned. But I'm happy to close this out

nvidia-jomiller avatar Feb 08 '25 00:02 nvidia-jomiller

Ok, thanks for confirming! Please leave this open for now, if nothing else I think we can merge in the test since more tests are always appreciated.

sunyab avatar Feb 08 '25 00:02 sunyab