Skip to content

Commit

Permalink
USD VolumeAlgo : Fix crash loading empty field
Browse files Browse the repository at this point in the history
If an attribute has no value, `DataAlgo::fromUSD()` returns `nullptr`, and we were dereferencing it. We could probably still use a `static_cast` here as long as we checked for null, since we don't expect anything but StringData when non-null. But since I failed to predict this outcome, I've gone belt-and-braces and used a `runTimeCast()`.
  • Loading branch information
johnhaddon committed Sep 18, 2024
1 parent ac82753 commit 97c19f0
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 97c19f0

Please sign in to comment.