Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions src/IECore/SceneCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,12 @@ class SceneCache::Implementation : public RefCounted
}
throw Exception( "File name not available in scene cache!" );
}


bool isFile() const
{
return m_indexedIO->typeId() == FileIndexedIOTypeId;
}

bool hasObject() const
{
return m_indexedIO->hasEntry( objectEntry );
Expand Down Expand Up @@ -1020,8 +1025,14 @@ class SceneCache::ReaderImplementation : public SceneCache::Implementation

static void sceneHash( const ReaderImplementation *scene, MurmurHash &h )
{
// \todo Currently there's a chance of hash collision if the file is closed and others opened, if the shared data object happens to be allocated in the same address. Replace it by a more reliable mechanism for uniquely identifying the file.
h.append( (uint64_t)scene->m_sharedData );
if( scene->isFile() )
{
h.append( scene->fileName() );
}
else
{
h.append( (uint64_t)scene->m_sharedData );
}
const ReaderImplementation *currScene = scene;
while( currScene->m_parent )
{
Expand Down
25 changes: 25 additions & 0 deletions test/IECore/SceneCacheTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -875,6 +875,31 @@ def checkHash( hashType, scene, currTime, duplicates = 0 ):
t1 = checkHash( IECore.SceneInterface.HashType.HierarchyHash, m, 1 )
self.assertEqual( t0[0] + t1[0], len(t0[1].union(t1[1])) ) # all locations differ

def testHashStability( self ) :

m = IECore.SceneCache( "test/IECore/data/sccFiles/animatedSpheres.scc", IECore.IndexedIO.OpenMode.Read )

def collectHashes( scene, hashType, time, hashResults ) :
counter = 1
h = scene.hash( hashType, time ).toString()
hashResults.add( h )
for n in scene.childNames() :
counter += collectHashes( scene.child(n), hashType, time, hashResults )
return counter

firstReadHashes = set()
collectHashes( m, IECore.SceneInterface.HashType.BoundHash, 0, firstReadHashes )
del m

secondReadHashes = set()
m = IECore.SceneCache( "test/IECore/data/sccFiles/animatedSpheres.scc", IECore.IndexedIO.OpenMode.Read )
collectHashes( m, IECore.SceneInterface.HashType.BoundHash, 0, secondReadHashes )
del m

self.assertEqual( firstReadHashes, secondReadHashes )




if __name__ == "__main__":
unittest.main()
Expand Down