Skip to content

Commit

Permalink
Merge pull request #1435 from johnhaddon/usdVolumeFix
Browse files Browse the repository at this point in the history
USD VolumeAlgo : Fix crash loading empty field
  • Loading branch information
ericmehl authored Sep 18, 2024
2 parents ac82753 + 97c19f0 commit 065d63d
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 2 deletions.
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"
{
}
}

0 comments on commit 065d63d

Please sign in to comment.