Commit c200ec93 authored by charras's avatar charras

Fixed: eeschemas sometimes crashes after a component with aliases is modified in libedit

parent b24118eb
......@@ -126,13 +126,13 @@ int LibraryEntryCompare( const CMP_LIB_ENTRY* aItem1, const CMP_LIB_ENTRY* aItem
* (like 74LS00, 74HC00 ... and many op amps )
*/
LIB_ALIAS::LIB_ALIAS( const wxString& aName, LIB_COMPONENT* aComponent,
LIB_ALIAS::LIB_ALIAS( const wxString& aName, LIB_COMPONENT* aRootComponent,
CMP_LIBRARY* aLibrary ) :
CMP_LIB_ENTRY( ALIAS, aName, aLibrary )
{
wxASSERT( aComponent != NULL && aComponent->isComponent() );
wxASSERT( aRootComponent != NULL && aRootComponent->isComponent() );
root = aComponent;
root = aRootComponent;
}
......
......@@ -515,11 +515,13 @@ protected:
* @note - Do not delete the root component. The root component is owned
* by library the component is part of. Deleting the root component
* will likely cause EESchema to crash.
* Or, if the root component is deleted, aliases must be deleted or their .root member
* must be changed to point a new root component
*/
LIB_COMPONENT* root;
public:
LIB_ALIAS( const wxString& aName, LIB_COMPONENT* aComponent,
LIB_ALIAS( const wxString& aName, LIB_COMPONENT* aRootComponent,
CMP_LIBRARY* aLibrary = NULL );
LIB_ALIAS( LIB_ALIAS& aAlias, CMP_LIBRARY* aLibrary = NULL );
~LIB_ALIAS();
......
......@@ -356,60 +356,43 @@ library <%s>" ),
LIB_COMPONENT* CMP_LIBRARY::ReplaceComponent( LIB_COMPONENT* aOldComponent,
LIB_COMPONENT* aNewComponent )
{
wxASSERT( aOldComponent != NULL && aNewComponent != NULL
&& aOldComponent->GetName().CmpNoCase( aNewComponent->GetName() )== 0 );
wxASSERT( aOldComponent != NULL );
wxASSERT( aNewComponent != NULL );
wxASSERT( aOldComponent->GetName().CmpNoCase( aNewComponent->GetName() )== 0 );
size_t i;
int index;
LIB_ALIAS* alias;
if( aOldComponent->m_AliasList != aNewComponent->m_AliasList )
{
/* Remove extra aliases. */
for( i = 0; i < aOldComponent->m_AliasList.GetCount(); i++ )
{
index =
aNewComponent->m_AliasList.Index( aOldComponent->m_AliasList[ i ] );
if( index != wxNOT_FOUND )
continue;
wxLogDebug( wxT( "Removing extra alias <%s> from component <%s> in library <%s>." ),
GetChars( aOldComponent->m_AliasList[ i ] ),
GetChars( aOldComponent->GetName() ),
GetChars( fileName.GetName() ) );
RemoveEntry( aOldComponent->m_AliasList[ i ] );
}
/* Add new aliases. */
for( i = 0; i < aNewComponent->m_AliasList.GetCount(); i++ )
{
index = aOldComponent->m_AliasList.Index( aNewComponent->m_AliasList[ i ] );
if( index != wxNOT_FOUND
|| FindEntry( aNewComponent->m_AliasList[ i ] ) != NULL )
continue;
LIB_COMPONENT* newCmp = new LIB_COMPONENT( *aNewComponent, this );
wxLogDebug( wxT( "Adding extra alias <%s> from component <%s> in library <%s>." ),
GetChars( aNewComponent->m_AliasList[ i ] ),
GetChars( aNewComponent->GetName() ),
GetChars( fileName.GetName() ) );
/* We want to remove the old root component, so we must remove old aliases.
* even if they are not modified, because their root component will be removed
*/
for( i = 0; i < aOldComponent->m_AliasList.GetCount(); i++ )
{
/* wxLogDebug( wxT( "Removing alias <%s> from component <%s> in library <%s>." ),
GetChars( aOldComponent->m_AliasList[ i ] ),
GetChars( aOldComponent->GetName() ),
GetChars( fileName.GetName() ) );
*/
RemoveEntry( aOldComponent->m_AliasList[ i ] );
}
alias = new LIB_ALIAS( aNewComponent->m_AliasList[ i ], aNewComponent );
entries.push_back( alias );
}
/* Now, add current aliases. */
for( i = 0; i < aNewComponent->m_AliasList.GetCount(); i++ )
{
/* wxLogDebug( wxT( "Adding alias <%s> from component <%s> in library <%s>." ),
GetChars( aNewComponent->m_AliasList[ i ] ),
GetChars( aNewComponent->GetName() ),
GetChars( fileName.GetName() ) );
*/
LIB_ALIAS* alias = new LIB_ALIAS( aNewComponent->m_AliasList[ i ], newCmp );
entries.push_back( alias );
}
RemoveEntry( aOldComponent->GetName() );
LIB_COMPONENT* newCmp = new LIB_COMPONENT( *aNewComponent, this );
if( newCmp == NULL )
return NULL;
entries.push_back( (CMP_LIB_ENTRY*) newCmp );
entries.sort();
isModified = true;
return newCmp;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment