Skip to content

Commit

Permalink
fixup! ContextTracker : Add asynchronous update mechanism
Browse files Browse the repository at this point in the history
Moved the check for a valid ScriptNode to `updateInBackground()`, since it may have been destroyed while we waited for the idle event.
  • Loading branch information
johnhaddon committed Jul 17, 2024
1 parent 77735d9 commit 198369f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
1 change: 1 addition & 0 deletions python/GafferUITest/ContextTrackerTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -711,6 +711,7 @@ def testAcquireForFocus( self ) :
self.assertTrue( tracker.isActive( script["add2" ] ) )

script.setFocus( None )
self.waitForIdle()
self.assertFalse( tracker.isActive( script["add1" ] ) )
self.assertFalse( tracker.isActive( script["add2" ] ) )

Expand Down
24 changes: 12 additions & 12 deletions src/GafferUI/ContextTracker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,17 +214,6 @@ void ContextTracker::scheduleUpdate()
// Cancel old update.
m_updateTask.reset();

if( !m_node || !m_node->scriptNode() )
{
// Don't need or can't use a BackgroundTask (the latter case being when
// a ScriptNode is being destroyed). Just do the update directly on the
// UI thread.
m_nodeContexts.clear();
m_plugContexts.clear();
changedSignal()( *this );
return;
}

// Arrange to do the update on the next idle event. This allows us to avoid
// redundant restarts when `plugDirtied()` or `contextChanged()` is called
// multiple times in quick succession.
Expand Down Expand Up @@ -255,10 +244,21 @@ void ContextTracker::updateInBackground()
}
}

if( toVisit.empty() || !m_node->scriptNode() )
{
// Don't need or can't use a BackgroundTask (the latter case being when
// a ScriptNode is being destroyed). Just do the update directly on the
// UI thread.
m_nodeContexts.clear();
m_plugContexts.clear();
changedSignal()( *this );
return;
}

Context::Scope scopedContext( contextCopy.get() );
m_updateTask = ParallelAlgo::callOnBackgroundThread(

/* subject = */ toVisit.empty() ? nullptr : toVisit.back().first,
/* subject = */ toVisit.back().first,

// OK to capture `this` without incrementing reference count, because
// ~UpstreamContext cancels background task and waits for it to
Expand Down

0 comments on commit 198369f

Please sign in to comment.