Skip to content

Commit 8b3385f

Browse files
committed
USD DataAlgo : Fix handling of types not known to dispatch()
We now return a sentinel instead of throwing an exception. This is consistent with our existing handling of types known to `dispatch()` but without a corresponding USD type.
1 parent b2526db commit 8b3385f

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

Changes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Fixes
1111

1212
- ShaderNetworkAlgo : Fixed crash caused by cyclic connections in `removeUnusedShaders()`.
1313
- ShaderStateComponent : Fixed GL rendering failures caused by unsupported values for texture parameters.
14+
- IECoreUSD::DataAlgo : Fixed exceptions thrown by `toUSD()` and `valueTypeName()` when passed datatypes not supported by `dispatch()`. An empty VtValue or SdfValueTypeName is now returned instead.
1415

1516
Build
1617
-----

contrib/IECoreUSD/src/IECoreUSD/DataAlgo.cpp

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,15 @@ struct VtValueFromData
400400

401401
pxr::VtValue IECoreUSD::DataAlgo::toUSD( const IECore::Data *data, bool arrayRequired )
402402
{
403-
return IECore::dispatch( data, VtValueFromData(), arrayRequired );
403+
try
404+
{
405+
return IECore::dispatch( data, VtValueFromData(), arrayRequired );
406+
}
407+
catch( const IECore::Exception & )
408+
{
409+
// Type not supported by `dispatch()`.
410+
return VtValue();
411+
}
404412
}
405413

406414
pxr::TfToken IECoreUSD::DataAlgo::role( GeometricData::Interpretation interpretation )
@@ -503,5 +511,13 @@ struct VtValueTypeNameFromData
503511

504512
pxr::SdfValueTypeName IECoreUSD::DataAlgo::valueTypeName( const IECore::Data *data )
505513
{
506-
return IECore::dispatch( data, VtValueTypeNameFromData() );
514+
try
515+
{
516+
return IECore::dispatch( data, VtValueTypeNameFromData() );
517+
}
518+
catch( const IECore::Exception & )
519+
{
520+
// Type not supported by `dispatch()`.
521+
return SdfValueTypeName();
522+
}
507523
}

contrib/IECoreUSD/test/IECoreUSD/DataAlgoTest.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
import unittest
3636
import imath
3737

38+
import pxr.Sdf
39+
3840
import IECore
3941
import IECoreUSD
4042

@@ -68,6 +70,9 @@ def testValueTypeNameBinding( self ) :
6870

6971
self.assertEqual( IECoreUSD.DataAlgo.valueTypeName( IECore.Color3fData( imath.Color3f( 0.0 ) ) ).type.typeName, "GfVec3f" )
7072

73+
self.assertEqual( IECoreUSD.DataAlgo.valueTypeName( IECore.PathMatcherData() ), pxr.Sdf.ValueTypeName() )
74+
self.assertEqual( IECoreUSD.DataAlgo.valueTypeName( IECore.CompoundData() ), pxr.Sdf.ValueTypeName() )
75+
7176
def testToUSDBinding( self ) :
7277

7378
# Note : On the C++ side we are converting to VtValue, but the
@@ -77,6 +82,8 @@ def testToUSDBinding( self ) :
7782
( IECore.IntData( 10 ), 10 ),
7883
( IECore.FloatData( 2.5 ), 2.5 ),
7984
( IECore.IntVectorData( [ 1, 2, 3 ] ), [ 1, 2, 3 ] ),
85+
( IECore.PathMatcherData(), None ),
86+
( IECore.CompoundData(), None ),
8087
] :
8188
self.assertEqual( IECoreUSD.DataAlgo.toUSD( data ), value )
8289

0 commit comments

Comments
 (0)