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

IECoreUSD : Use / for asset paths #1426

Closed
wants to merge 5 commits into from

Conversation

ericmehl
Copy link
Collaborator

This fixes a bug where asset and volume paths were using \ on Windows. This meant that doing string substitution would lead to interpreting the \ as the start of an escape sequence.

This came up for a user using a ShaderQuery node in Gaffer. ShaderQuery sets the default texture path for a query from the USD asset name, and the built-in string substitution will cause the \\ to be collapsed into a single \, the start of an escape sequence and an incorrect file name.

I think this can be considered a bug fix rather than a breaking change? If it would be better to consider it a breaking change I can retarget to main.

Checklist

  • I have read the contribution guidelines.
  • I have updated the documentation, if applicable.
  • I have tested my change(s) in the test suite, and added new test cases where necessary.
  • My code follows the Cortex project's prevailing coding style and conventions.

@ericmehl
Copy link
Collaborator Author

Forgot to post the other day - I made the replacing of slashes contingent on the environment variable IECOREUSD_FORCE_ASSET_PATH_FORWARD_SLASH, defaulting to True if it's not found. A bit of a wordy variable name, but I think the extra clarify and hopefully rare need for it make it worth it.

@ericmehl ericmehl force-pushed the USDSlashWindows branch 2 times, most recently from 019efe1 to c775c99 Compare July 30, 2024 15:10
@ericmehl
Copy link
Collaborator Author

Thanks @johnhaddon! I think I have a nice efficient solution with the DataAlgo::fromUSD() method now. And on Linux this sticks with the original behavior now.

Ready for a new look.

Copy link
Member

@johnhaddon johnhaddon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry Eric, this one dropped off my radar somehow. I've made some new comments inline, including something I missed in the first place, and which I think makes what we're trying to do a little bit simpler...

contrib/IECoreUSD/src/IECoreUSD/VolumeAlgo.cpp Outdated Show resolved Hide resolved
contrib/IECoreUSD/src/IECoreUSD/DataAlgo.cpp Outdated Show resolved Hide resolved
contrib/IECoreUSD/test/IECoreUSD/USDSceneTest.py Outdated Show resolved Hide resolved
On Windows, the result of USD's `GetResolvedPath()` method returns the
resolved path using `\` between directories. This can cause problems
when doing string substition on a resolved path since the `\` will be
interpreted as the start of an escape character. Using `/` also
conforms to Cortex's standard of always using `/` for paths because they
work on all operating systems.
@ericmehl
Copy link
Collaborator Author

Sorry Eric, this one dropped off my radar somehow.

No worries, these are nice improvements. I addressed the new comments, ready for another look!

Copy link
Member

@johnhaddon johnhaddon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the update Eric - almost there! (See comments inline).

fieldAsset.GetFilePathAttr().Get( &fieldAssetPath, time );
const std::string fieldFileName = fieldAssetPath.GetResolvedPath();
ConstDataPtr fieldFileNameData = DataAlgo::fromUSD( fieldAsset.GetFilePathAttr(), time );
const std::string fieldFileName = runTimeCast<const StringData>( fieldFileNameData )->readable();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

runTimeCast should always be accompanied with a check for null - by using runTimeCast you are saying that you don't know what the type is. I think it would be reasonable to use static_cast or assertStaticCast here though, since we know the result type.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I was not quite clear on when to use runTimeCast vs static_cast, thanks for that explanation. I went with static_cast in ffe4507 since dataFromSdfAssetPath() always returns at least an empty StringData.

@@ -169,7 +193,7 @@ IECore::DataPtr dataFromSdfAssetPath( const SdfAssetPath &assetPath, const pxr::
)
{
return new StringData(
SdfComputeAssetPathRelativeToLayer( spec->GetLayer(), assetPath.GetAssetPath() )
SdfComputeAssetPathRelativeToLayer( spec->GetLayer(), p )
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

p is derived from GetResolvedPath(), but we need to continue to pass GetAssetPath() here. I think this is most likely responsible for the CI failure.

I also wonder if SdfComputeAssetPathRelativeToLayer() might introduces \ of its own? Maybe it's better to do the substitutions on the result than the argument?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, that makes sense. Fixed in 041cfa7

@ericmehl
Copy link
Collaborator Author

Ok, got the tests passing again and I think now have all the fixups made.

@johnhaddon
Copy link
Member

Thanks for the update. I've squashed and merged this via command line, since I didn't have permissions to push a squashed version to the PR for some reason.

@johnhaddon johnhaddon closed this Sep 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants