Skip to content

Commit

Permalink
fixup! ContextTracker : Add asynchronous update mechanism
Browse files Browse the repository at this point in the history
  • Loading branch information
johnhaddon committed Jul 17, 2024
1 parent 77735d9 commit 4ed9d2a
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions src/GafferUI/ContextTracker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,26 +205,34 @@ const Gaffer::Context *ContextTracker::targetContext() const

void ContextTracker::scheduleUpdate()
{
if( m_idleConnection.connected() )
{
// Update already scheduled.
return;
}

// Cancel old update.
m_updateTask.reset();

if( !m_node || !m_node->scriptNode() )
if( !m_node )
{
// 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.
// Don't need a BackgroundTask, so just do the update directly on the UI
// thread.
m_nodeContexts.clear();
m_plugContexts.clear();
m_idleConnection.disconnect();
changedSignal()( *this );
return;
}

if( !m_node->scriptNode() )
{
// ScriptNode is dying. Can't use a BackgroundTask and no need for
// update anyway.
m_idleConnection.disconnect();
return;
}

if( m_idleConnection.connected() )
{
// Update already scheduled.
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

0 comments on commit 4ed9d2a

Please sign in to comment.