From b338dfdccb021576753b6ee49ad4218c41fea0c2 Mon Sep 17 00:00:00 2001 From: charras Date: Wed, 3 Mar 2010 15:56:08 +0000 Subject: [PATCH] Fixed bug 2962142 (Eeschema: Crash SaveEEFile on demo) --- eeschema/class_library.cpp | 28 +++++++++++++++++----------- eeschema/libarch.cpp | 10 +++++++--- 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/eeschema/class_library.cpp b/eeschema/class_library.cpp index ab72efac22..59248e4236 100644 --- a/eeschema/class_library.cpp +++ b/eeschema/class_library.cpp @@ -229,14 +229,12 @@ bool CMP_LIBRARY::AddAlias( LIB_ALIAS* aAlias ) */ LIB_COMPONENT* CMP_LIBRARY::AddComponent( LIB_COMPONENT* aComponent ) { - wxASSERT( aComponent != NULL ); + if( aComponent == NULL ) + return NULL; LIB_COMPONENT* newCmp = new LIB_COMPONENT( *aComponent, this ); newCmp->ClearAliasDataDoc(); // Remove data used only in edition - if( newCmp == NULL ) - return NULL; - // Conflict detection: See if already existing aliases exist, // and if yes, ask user for continue or abort // Special case: if the library is the library cache of the project, @@ -252,13 +250,15 @@ LIB_COMPONENT* CMP_LIBRARY::AddComponent( LIB_COMPONENT* aComponent ) if( alias == NULL ) continue; + LIB_COMPONENT* cparent = alias->GetComponent(); - if( alias->GetComponent()->GetName().CmpNoCase( newCmp->GetName() ) != 0 ) + if( cparent == NULL || // Lib error, should not occurs + ( cparent->GetName().CmpNoCase( newCmp->GetName() ) != 0 ) ) { wxString msg1; msg1.Printf( _("alias <%s> already exists and has root name<%s>"), GetChars( alias->GetName() ), - GetChars( alias->GetComponent()->GetName() ) ); + GetChars( cparent ? cparent->GetName() : _("unknown") ) ); msg << msg1 << wxT("\n"); conflict_count++; } @@ -292,12 +292,18 @@ LIB_COMPONENT* CMP_LIBRARY::AddComponent( LIB_COMPONENT* aComponent ) alias = new LIB_ALIAS( aliasname, newCmp ); entries.push_back( alias ); } - else if( alias->GetComponent()->GetName().CmpNoCase( newCmp->GetName() ) != 0 ) + else { - // Remove alias from library and alias list of its root component - RemoveEntry( alias ); - alias = new LIB_ALIAS( aliasname, newCmp ); - entries.push_back( alias ); + LIB_COMPONENT* cparent = alias->GetComponent(); + + if( cparent == NULL || // Lib error, should not occurs + ( cparent->GetName().CmpNoCase( newCmp->GetName() ) != 0) ) + { + // Remove alias from library and alias list of its root component + RemoveEntry( alias ); + alias = new LIB_ALIAS( aliasname, newCmp ); + entries.push_back( alias ); + } } // Update alias data: alias->SetDescription( aComponent->GetAliasDataDoc( aliasname ) ); diff --git a/eeschema/libarch.cpp b/eeschema/libarch.cpp index a0d56dbd42..e6f601cdfe 100644 --- a/eeschema/libarch.cpp +++ b/eeschema/libarch.cpp @@ -43,10 +43,14 @@ bool LibArchive( wxWindow* frame, const wxString& ArchFullFileName ) continue; SCH_COMPONENT* component = (SCH_COMPONENT*) SchItem; - Entry = CMP_LIBRARY::FindLibraryComponent( component->m_ChipName ); + // If not already saved in the new cache, put it: + if( libCache->FindEntry( component->m_ChipName) == NULL ) + { + Entry = CMP_LIBRARY::FindLibraryComponent( component->m_ChipName ); - if( Entry ) // if NULL : component not found - libCache->AddComponent( Entry ); + if( Entry ) // if NULL : component not found, cannot be stored + libCache->AddComponent( Entry ); + } } }