From 7a10feb35d4bb572fe5f4a1b699154714e03b733 Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Sun, 19 Aug 2018 10:25:12 +0200 Subject: [PATCH] Libedit: Fix a crash when trying to revert changes in a library (No crash when reverting changes in a part, only in a library) Fixes: lp:1787772 https://bugs.launchpad.net/kicad/+bug/1787772 --- eeschema/libedit.cpp | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/eeschema/libedit.cpp b/eeschema/libedit.cpp index 5a978a9fd0..610010c52f 100644 --- a/eeschema/libedit.cpp +++ b/eeschema/libedit.cpp @@ -542,15 +542,29 @@ void LIB_EDIT_FRAME::OnRevert( wxCommandEvent& aEvent ) { LIB_ID libId = getTargetLibId(); const wxString& libName = libId.GetLibNickname(); - const wxString& partName = libId.GetLibItemName(); + const wxString& partName = libId.GetLibItemName(); // Empty if this is the library itself that is selected if( !IsOK( this, _( "The revert operation cannot be undone!\n\nRevert changes?" ) ) ) return; - bool currentPart = isCurrentPart( libId ); + bool reload_currentPart; + wxString curr_partName = partName; + + // the library itself is reverted: the current part will be reloaded only if it is owned by this library + if( partName.IsEmpty() ) + { + LIB_ID curr_libId = GetCurPart()->GetLibId(); + reload_currentPart = libName == curr_libId.GetLibNickname(); + + if( reload_currentPart ) + curr_partName = curr_libId.GetLibItemName(); + } + else + reload_currentPart = isCurrentPart( libId ); + int unit = m_unit; - if( currentPart ) + if( reload_currentPart ) emptyScreen(); if( partName.IsEmpty() ) @@ -565,8 +579,8 @@ void LIB_EDIT_FRAME::OnRevert( wxCommandEvent& aEvent ) m_libMgr->ClearPartModified( libId.GetLibItemName(), libId.GetLibNickname() ); } - if( currentPart && m_libMgr->PartExists( partName, libName ) ) - loadPart( partName, libName, unit ); + if( reload_currentPart && m_libMgr->PartExists( curr_partName, libName ) ) + loadPart( curr_partName, libName, unit ); m_treePane->Refresh(); }