Skip to content

Commit

Permalink
Merge pull request #2886 from johnhaddon/instancerFix
Browse files Browse the repository at this point in the history
Instancer : Fix division by zero bug
  • Loading branch information
andrewkaufman committed Nov 2, 2018
2 parents 5bc0c86 + 55d070a commit 37eb5fd
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
12 changes: 12 additions & 0 deletions python/GafferSceneTest/InstancerTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -945,5 +945,17 @@ def testEditAttributes( self ) :
} )
)

def testUnconnectedInstanceInput( self ) :

plane = GafferScene.Plane()
plane["sets"].setValue( "A" )
plane["divisions"].setValue( imath.V2i( 1, 500 ) )

instancer = GafferScene.Instancer()
instancer["in"].setInput( plane["out"] )
instancer["parent"].setValue( "/plane" )

self.assertEqual( instancer["out"].set( "A" ).value.paths(), [ "/plane" ] )

if __name__ == "__main__":
unittest.main()
9 changes: 6 additions & 3 deletions src/GafferScene/Instancer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -592,10 +592,13 @@ void Instancer::compute( Gaffer::ValuePlug *output, const Gaffer::Context *conte
indexedInstanceChildNames.push_back( &instanceChildNames->writable() );
}

for( size_t i = 0, e = engine->numPoints(); i < e; ++i )
if( indexedInstanceChildNames.size() )
{
size_t instanceIndex = engine->instanceIndex( i ) % indexedInstanceChildNames.size();
indexedInstanceChildNames[instanceIndex]->push_back( InternedString( engine->instanceId( i ) ) );
for( size_t i = 0, e = engine->numPoints(); i < e; ++i )
{
size_t instanceIndex = engine->instanceIndex( i ) % indexedInstanceChildNames.size();
indexedInstanceChildNames[instanceIndex]->push_back( InternedString( engine->instanceId( i ) ) );
}
}

static_cast<AtomicCompoundDataPlug *>( output )->setValue( result );
Expand Down

0 comments on commit 37eb5fd

Please sign in to comment.