Skip to content

Commit

Permalink
Reference : Make m_plugEdits key more unique
Browse files Browse the repository at this point in the history
On Windows in particular, and it's conceivable that it could happen on
Linux, `plugEdit()` would occasionally find an edit for a plug where
none should exist. This was due the memory address of the plug, used as
a key for `m_plugEdits`, for a newly created plug was the same as a
recently deleted plug.

This was causing a test failure in
`GafferTest.ReferenceTest.testAddingChildPlugs` on Windows with
something like 1 : 1000 probability.
  • Loading branch information
ericmehl committed Oct 19, 2023
1 parent b8cb5f1 commit cc7c02b
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/Gaffer/Reference.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -312,15 +312,15 @@ class Reference::PlugEdits : public Signals::Trackable
int64_t sizeAfterLoad = -1; // Default value means size not tracked
};

std::unordered_map<const Plug*, PlugEdit> m_plugEdits;
std::unordered_map<ConstPlugPtr, PlugEdit> m_plugEdits;

const PlugEdit *plugEdit( const Plug *plug ) const
{
// Cheeky cast better than maintaining two near-identical functions.
return const_cast<PlugEdits *>( this )->plugEdit( plug, /* createIfMissing = */ false );
}

PlugEdit *plugEdit( const Plug *plug, bool createIfMissing )
PlugEdit *plugEdit( ConstPlugPtr plug, bool createIfMissing )
{
if( plug->node() != m_reference )
{
Expand All @@ -333,7 +333,7 @@ class Reference::PlugEdits : public Signals::Trackable
return &(it->second);
}

if( !m_reference->isReferencePlug( plug ) )
if( !m_reference->isReferencePlug( plug.get() ) )
{
// We'll allow retrieval of existing edits on this plug, but we
// won't create new ones.
Expand Down

0 comments on commit cc7c02b

Please sign in to comment.