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

USD VolumeAlgo : Fix crash loading empty field #1435

Merged
merged 1 commit into from
Sep 18, 2024
Merged
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
3 changes: 3 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
10.5.x.x (relative to 10.5.9.3)
========

Fixes
-----

- USDScene : Fixed crash loading a Volume with an empty field.

10.5.9.3 (relative to 10.5.9.2)
========
Expand Down
7 changes: 5 additions & 2 deletions contrib/IECoreUSD/src/IECoreUSD/VolumeAlgo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,11 @@ IECore::ObjectPtr readVolume( pxr::UsdVolVolume &volume, pxr::UsdTimeCode time,
continue;
}

ConstDataPtr fieldFileNameData = DataAlgo::fromUSD( fieldAsset.GetFilePathAttr(), time );
const std::string fieldFileName = static_cast<const StringData *>( fieldFileNameData.get() )->readable();
std::string fieldFileName;
if( auto fieldFileNameData = runTimeCast<const StringData>( DataAlgo::fromUSD( fieldAsset.GetFilePathAttr(), time ) ) )
{
fieldFileName = fieldFileNameData->readable();
}

if( fileName.empty() )
{
Expand Down
7 changes: 7 additions & 0 deletions contrib/IECoreUSD/test/IECoreUSD/USDSceneTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4398,5 +4398,12 @@ def testUsdVolVolumeSlashes( self ) :
self.assertNotIn( "\\", vdbObject.fileName() )
self.assertTrue( pathlib.Path( vdbObject.fileName() ).is_file() )

@unittest.skipIf( not haveVDB, "No IECoreVDB" )
def testUsdVolVolumeWithEmptyField( self ) :

fileName = os.path.dirname( __file__ ) + "/data/volumeWithEmptyField.usda"
root = IECoreScene.SceneInterface.create( fileName, IECore.IndexedIO.OpenMode.Read )
self.assertIsNone( root.child( "volume" ).readObject( 0 ) )

if __name__ == "__main__":
unittest.main()
11 changes: 11 additions & 0 deletions contrib/IECoreUSD/test/IECoreUSD/data/volumeWithEmptyField.usda
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#usda 1.0

def Volume "volume"
{
custom rel field:density = </volume/density>

def OpenVDBAsset "density"
{
}
}

Loading