Skip to content

Commit 0936662

Browse files
committed
Fixed a bug with IECoreNuke::SceneCacheReader that was causing hanging and crashing.
1 parent 8165a25 commit 0936662

File tree

2 files changed

+57
-22
lines changed

2 files changed

+57
-22
lines changed

include/IECoreNuke/SceneCacheReader.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ class SceneCacheReader : public DD::Image::SourceGeo
130130
void rebuildSelection();
131131
/// Clear any selected geometry from the SceneView_knob.
132132
void clearSceneViewSelection();
133-
/// Clears the current filters applied to the scene..
133+
/// Clears the current filters applied to the scene.
134134
void clearSceneViewFilter();
135135
//@}
136136

@@ -186,7 +186,10 @@ class SceneCacheReader : public DD::Image::SourceGeo
186186
DD::Image::Knob *m_rootKnob;
187187

188188
// A flag which is set when all of the knobs have been loaded from the script.
189-
bool m_scriptLoaded;
189+
bool m_scriptFinishedLoading;
190+
191+
// A flag which is used to initialize the internal data structures the first time the node is run.
192+
bool m_isFirstRun;
190193

191194
/// The SceneView_knob holds a list of all leaf items in the scene. When filtering the SceneView we specify indices into
192195
/// this list. When setting or querying the selected items in the SceneView_knob we need to use indices into the list of

src/IECoreNuke/SceneCacheReader.cpp

Lines changed: 52 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,8 @@ SceneCacheReader::SceneCacheReader( Node *node )
111111
m_tagFilterKnob( NULL ),
112112
m_sceneFilterKnob( NULL ),
113113
m_rootKnob( NULL ),
114-
m_scriptLoaded( false )
114+
m_scriptFinishedLoading( false ),
115+
m_isFirstRun( true )
115116
{
116117
m_baseParentMatrix.makeIdentity();
117118
}
@@ -123,16 +124,25 @@ SceneCacheReader::~SceneCacheReader()
123124
void SceneCacheReader::_validate( bool forReal )
124125
{
125126
m_evaluatedFilePath = filePath();
126-
127-
if( !m_scriptLoaded )
127+
128+
if( m_scriptFinishedLoading )
128129
{
129-
knob("loadAll")->set_value( true );
130-
m_scriptLoaded = true;
131-
loadAllFromKnobs();
132-
}
130+
if( m_isFirstRun )
131+
{
132+
Knob *k = knob("loadAll");
133+
if( k != NULL )
134+
{
135+
k->set_value( true );
136+
}
133137

134-
filterScene( m_filterText, m_filterTagText );
135-
rebuildSelection();
138+
m_isFirstRun = false;
139+
m_scriptFinishedLoading = true;
140+
loadAllFromKnobs();
141+
}
142+
143+
filterScene( m_filterText, m_filterTagText );
144+
rebuildSelection();
145+
}
136146

137147
SourceGeo::_validate( forReal );
138148
}
@@ -154,7 +164,7 @@ void SceneCacheReader::knobs( DD::Image::Knob_Callback f )
154164
);
155165

156166
int p = 0;
157-
const char* tagNames[4] = { "None", 0 };
167+
const char* tagNames[2] = { "None", 0 };
158168
m_tagFilterKnob = Enumeration_knob( f, &p, tagNames, "filterByTag", "Filter Tag" );
159169
SetFlags( f, DD::Image::Knob::ALWAYS_SAVE | DD::Image::Knob::KNOB_CHANGED_ALWAYS );
160170
Tooltip( f,
@@ -322,12 +332,9 @@ int SceneCacheReader::knob_changed(Knob* k)
322332
// structures.
323333
else if( knob("loadAll") == k )
324334
{
325-
return 1;
326-
if( !m_scriptLoaded )
335+
if( !m_scriptFinishedLoading )
327336
{
328-
knob("loadAll")->set_value( true );
329-
m_scriptLoaded = true;
330-
loadAllFromKnobs();
337+
m_scriptFinishedLoading = true;
331338
}
332339

333340
return 1;
@@ -339,7 +346,7 @@ int SceneCacheReader::knob_changed(Knob* k)
339346

340347
void SceneCacheReader::loadAllFromKnobs()
341348
{
342-
if( !m_scriptLoaded )
349+
if( !m_scriptFinishedLoading )
343350
{
344351
throw IECore::Exception( "SceneCacheReader: Cannot load item as the script hasn't finished loading." );
345352
}
@@ -350,7 +357,8 @@ void SceneCacheReader::loadAllFromKnobs()
350357

351358
std::vector<unsigned int> selectionIndices;
352359
sceneView->getSelectedItems( selectionIndices );
353-
360+
361+
354362
std::vector<unsigned int> filterIndices;
355363
sceneView->getImportedItems( filterIndices );
356364

@@ -396,7 +404,15 @@ void SceneCacheReader::loadAllFromKnobs()
396404

397405
void SceneCacheReader::rebuildSelection()
398406
{
399-
if( !m_scriptLoaded ) return;
407+
if( !m_scriptFinishedLoading )
408+
{
409+
return;
410+
}
411+
412+
if( m_isFirstRun )
413+
{
414+
validate( false );
415+
}
400416

401417
// We require an up-to-date scene so rebuild it if necessary.
402418
rebuildSceneView();
@@ -461,7 +477,15 @@ void SceneCacheReader::rebuildSceneView()
461477
{
462478
m_evaluatedFilePath = filePath();
463479

464-
if( !m_scriptLoaded ) return;
480+
if( !m_scriptFinishedLoading )
481+
{
482+
return;
483+
}
484+
485+
if( m_isFirstRun )
486+
{
487+
validate( false );
488+
}
465489

466490
Hash newSceneHash( sceneHash() );
467491

@@ -530,7 +554,15 @@ const std::string &SceneCacheReader::itemName( int index ) const
530554
// There LUTs are the m_itemToFiltered and m_filteredToItem maps.
531555
void SceneCacheReader::filterScene( const std::string &filterText, const std::string &filterTag )
532556
{
533-
if( !m_scriptLoaded ) return;
557+
if( !m_scriptFinishedLoading )
558+
{
559+
return;
560+
}
561+
562+
if( m_isFirstRun )
563+
{
564+
validate( false );
565+
}
534566

535567
Hash newFilterHash( sceneHash() );
536568
newFilterHash.append( filterText );

0 commit comments

Comments
 (0)