Skip to content

Commit

Permalink
Fixed SceneReader behaviour for invalid files and paths.
Browse files Browse the repository at this point in the history
Previously, it would throw an exception on the first attempt, and then either silently fail or crash on subsequent attempts. This was because we were updating the fileName/path fields in LastScene _before_ the operations which might throw, rather than after. By only updating them after, they remain in sync with the true state of the corresponding fileNameScene/pathScene fields.
  • Loading branch information
johnhaddon committed Jan 8, 2015
1 parent 5ae3ba1 commit 6de146b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
19 changes: 19 additions & 0 deletions python/GafferSceneTest/SceneReaderTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,25 @@ def testTagsAsSets( self ) :
self.assertEqual( sets["wood"].value.paths(), [ "/planeGroup/plane" ] )
self.assertEqual( sets["something"].value.paths(), [ "/planeGroup/plane" ] )

def testInvalidFiles( self ) :

reader = GafferScene.SceneReader()
reader["fileName"].setValue( "iDontExist.scc" )

for i in range( 0, 10 ) :
self.assertRaises( RuntimeError, GafferSceneTest.traverseScene, reader["out"], Gaffer.Context() )

def testInvalidPaths( self ) :

self.writeAnimatedSCC()

reader = GafferScene.SceneReader()
reader["fileName"].setValue( self.__testFile )
reader["refreshCount"].setValue( self.uniqueInt( self.__testFile ) )

for i in range( 0, 10 ) :
self.assertRaises( RuntimeError, reader["out"].object, "/this/object/does/not/exist" )

def tearDown( self ) :

if os.path.exists( self.__testFile ) :
Expand Down
8 changes: 5 additions & 3 deletions src/GafferScene/SceneReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -525,15 +525,17 @@ ConstSceneInterfacePtr SceneReader::scene( const ScenePath &path ) const
}
else
{
lastScene.path = path;
lastScene.pathScene = lastScene.fileNameScene->scene( path );
lastScene.path = path;
return lastScene.pathScene;
}
}

lastScene.fileName = fileName;
lastScene.fileNameScene = SharedSceneInterfaces::get( fileName );
lastScene.path = path;
lastScene.fileName = fileName;

lastScene.pathScene = lastScene.fileNameScene->scene( path );
lastScene.path = path;

return lastScene.pathScene;
}

0 comments on commit 6de146b

Please sign in to comment.