From d7a4fb7d8b2fe03a57e52601c4ea8cf0b5611418 Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Sun, 9 Jul 2017 20:17:18 +0200 Subject: [PATCH] Fix a crash in Eeschema when creating a netlist just after saving the project. This is more a workaround than a fix. The crash was due to the fact the library cache is modified on the disk with the saving process. Fixes: lp:1702707 https://bugs.launchpad.net/kicad/+bug/1702707 --- eeschema/class_library.h | 12 +++++++++++- eeschema/class_sch_screen.h | 9 +++++++++ eeschema/libarch.cpp | 20 +++++++++++++++++--- 3 files changed, 37 insertions(+), 4 deletions(-) diff --git a/eeschema/class_library.h b/eeschema/class_library.h index 5ffa0655fd..6bb5f12f7b 100644 --- a/eeschema/class_library.h +++ b/eeschema/class_library.h @@ -146,7 +146,7 @@ public: /** * Function GetLibSource - * @return the name of the lib to use to load a part, or an a emty string + * @return the name of the lib to use to load a part, or an a empty string * Useful to load (in lib editor or lib viewer) a part from a given library */ const wxString& GetLibSource() const @@ -339,8 +339,18 @@ public: SCH_IO_MGR::SCH_FILE_T aPluginType = SCH_IO_MGR::SCH_LEGACY ); ~PART_LIB(); + /** + * @return a magic number that changes if the library has changed + */ int GetModHash() const { return m_mod_hash; } + /** + * Forces a change of the magic number that usually changes + * if the library has changed. Usefull to force initializations + * only made on library change. + */ + void IncModHash() { ++m_mod_hash; } + SCH_IO_MGR::SCH_FILE_T GetPluginType() const { return m_pluginType; } void SetPluginType( SCH_IO_MGR::SCH_FILE_T aPluginType ); diff --git a/eeschema/class_sch_screen.h b/eeschema/class_sch_screen.h index 0886c6a1f9..82c95948ca 100644 --- a/eeschema/class_sch_screen.h +++ b/eeschema/class_sch_screen.h @@ -587,7 +587,16 @@ public: int GetMarkerCount( enum MARKER_BASE::TYPEMARKER aMarkerType, enum MARKER_BASE::MARKER_SEVERITY aSeverity ); + /** + * initializes or reinitializes the weak reference + * to the LIB_PART for each SCH_COMPONENT found in the full schematic + * It must be called from: + * - Draw function + * - when loading a schematic file + * - before creating a netlist (in case a library is modified) + */ void UpdateSymbolLinks(); + void TestDanglingEnds(); /** diff --git a/eeschema/libarch.cpp b/eeschema/libarch.cpp index 89a3c53a98..81adc63ca8 100644 --- a/eeschema/libarch.cpp +++ b/eeschema/libarch.cpp @@ -52,7 +52,21 @@ bool SCH_EDIT_FRAME::CreateArchiveLibraryCacheFile( bool aUseCurrentSheetFilenam fn.SetName( fn.GetName() + "-cache" ); fn.SetExt( SchematicLibraryFileExtension ); - return CreateArchiveLibrary( fn.GetFullPath() ); + bool success = CreateArchiveLibrary( fn.GetFullPath() ); + + // Mark the library cache as modified: + PART_LIBS* libs = Prj().SchLibs(); + PART_LIB* libcache = libs->FindLibrary( fn.GetName() ); + + if( libcache ) + libcache->IncModHash(); + + // Update the schematic symbol library links. + // because the lib cache has changed + SCH_SCREENS schematic; + schematic.UpdateSymbolLinks(); + + return success; } @@ -65,8 +79,8 @@ bool SCH_EDIT_FRAME::CreateArchiveLibrary( const wxString& aFileName ) // Create a new empty library to archive components: std::unique_ptr archLib( new PART_LIB( LIBRARY_TYPE_EESCHEMA, aFileName ) ); - archLib->SetCache(); - archLib->EnableBuffering(); // To save symbols to file only when the library will be fully filled + // Save symbols to file only when the library will be fully filled + archLib->EnableBuffering(); /* Examine all screens (not hierarchical sheets) used in the schematic and build a * library of unique symbols found in all screens. Complex hierarchies are not a