Skip to content

Commit dc9585a

Browse files
committed
SceneCacheFileFormat: Handle invalid file path.
Handle the exception to avoid crashing the application.
1 parent 643f16a commit dc9585a

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

contrib/IECoreUSD/src/IECoreUSD/SceneCacheFileFormat.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,11 @@ bool UsdSceneCacheFileFormat::WriteToFile( const SdfLayer& layer, const std::str
175175
SceneInterfacePtr outScene;
176176

177177
outScene = SdfFileFormatSharedSceneWriters::get( filePath );
178+
if ( !outScene )
179+
{
180+
IECore::msg( IECore::Msg::Error, "UsdSceneCacheFileFormat::WriteToFile", boost::format( "Invalid file path \"%s\" for layer \"%s\"." ) % filePath % layer.GetIdentifier() );
181+
return false;
182+
}
178183

179184
SceneInterface::NameList childNames;
180185
usdScene->childNames( childNames );

contrib/IECoreUSD/src/IECoreUSD/SdfFileFormatSharedSceneWriters.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include "SdfFileFormatSharedSceneWriters.h"
3636

3737
#include "IECore/LRUCache.h"
38+
#include "IECore/MessageHandler.h"
3839

3940
using namespace IECore;
4041
using namespace IECoreScene;
@@ -61,7 +62,15 @@ class Cache : public SceneLRUCache
6162

6263
static SceneInterfacePtr fileCacheGetter( const std::string &fileName, size_t &cost )
6364
{
64-
SceneInterfacePtr result = SceneInterface::create( fileName, IECore::IndexedIO::Write );
65+
SceneInterfacePtr result = nullptr;
66+
try
67+
{
68+
result = SceneInterface::create( fileName, IECore::IndexedIO::Write );
69+
}
70+
catch ( ... )
71+
{
72+
IECore::msg( IECore::Msg::Error, "SdfFileFormatSharedSceneWriters::SceneLRUCache", boost::format( "Unable to open file path \"%s\" for writing IndexedIo data." ) % fileName );
73+
}
6574
cost = 1;
6675
return result;
6776
}

0 commit comments

Comments
 (0)