Commit 659ea518 authored by Dick Hollenbeck's avatar Dick Hollenbeck Committed by Wayne Stambaugh

Fix Eeschema search segfault.

* The SCH_COLLECTOR m_foundItems was being obsoleted after a pin name search.
  If a library edit changed the found pin name, the cache still held the now
  missing library pin and would segfault on next search due to the cache being
  out of date.
parent ea11c013
...@@ -131,7 +131,7 @@ public: ...@@ -131,7 +131,7 @@ public:
* @return True if \a aFindReplaceData would result in a search and/or replace change, * @return True if \a aFindReplaceData would result in a search and/or replace change,
* otherwise false. * otherwise false.
*/ */
bool ChangesCompare( SCH_FIND_REPLACE_DATA& aFindReplaceData ) bool ChangesCompare( const SCH_FIND_REPLACE_DATA& aFindReplaceData )
{ {
return ( (GetFindString() != aFindReplaceData.GetFindString()) return ( (GetFindString() != aFindReplaceData.GetFindString())
|| (GetCompareFlags() != aFindReplaceData.GetCompareFlags()) ); || (GetCompareFlags() != aFindReplaceData.GetCompareFlags()) );
......
...@@ -285,6 +285,25 @@ SCH_ITEM* SCH_EDIT_FRAME::FindComponentAndItem( const wxString& aReference, ...@@ -285,6 +285,25 @@ SCH_ITEM* SCH_EDIT_FRAME::FindComponentAndItem( const wxString& aReference,
} }
bool SCH_EDIT_FRAME::IsSearchCacheObsolete( const SCH_FIND_REPLACE_DATA& aSearchCriteria )
{
PART_LIBS* libs = Prj().SchLibs();
int mod_hash = libs->GetModifyHash();
// the cache is obsolete whenever any library changes.
if( mod_hash != m_foundItems.GetLibHash() )
{
m_foundItems.SetForceSearch();
m_foundItems.SetLibHash( mod_hash );
return true;
}
else if( m_foundItems.IsSearchRequired( aSearchCriteria ) )
return true;
else
return false;
}
void SCH_EDIT_FRAME::OnFindSchematicItem( wxFindDialogEvent& aEvent ) void SCH_EDIT_FRAME::OnFindSchematicItem( wxFindDialogEvent& aEvent )
{ {
static wxPoint itemPosition; // the actual position of the matched item. static wxPoint itemPosition; // the actual position of the matched item.
...@@ -303,7 +322,7 @@ void SCH_EDIT_FRAME::OnFindSchematicItem( wxFindDialogEvent& aEvent ) ...@@ -303,7 +322,7 @@ void SCH_EDIT_FRAME::OnFindSchematicItem( wxFindDialogEvent& aEvent )
if( m_foundItems.GetCount() == 0 ) if( m_foundItems.GetCount() == 0 )
return; return;
} }
else if( m_foundItems.IsSearchRequired( searchCriteria ) ) else if( IsSearchCacheObsolete( searchCriteria ) )
{ {
if( aEvent.GetFlags() & FR_CURRENT_SHEET_ONLY && g_RootSheet->CountSheets() > 1 ) if( aEvent.GetFlags() & FR_CURRENT_SHEET_ONLY && g_RootSheet->CountSheets() > 1 )
{ {
......
...@@ -467,7 +467,7 @@ bool SCH_FIND_COLLECTOR::ReplaceItem( SCH_SHEET_PATH* aSheetPath ) ...@@ -467,7 +467,7 @@ bool SCH_FIND_COLLECTOR::ReplaceItem( SCH_SHEET_PATH* aSheetPath )
bool replaced = item->Replace( m_findReplaceData, aSheetPath ); bool replaced = item->Replace( m_findReplaceData, aSheetPath );
if( replaced ) if( replaced )
m_forceSearch = true; SetForceSearch();
return replaced; return replaced;
} }
...@@ -512,7 +512,7 @@ void SCH_FIND_COLLECTOR::Collect( SCH_FIND_REPLACE_DATA& aFindReplaceData, ...@@ -512,7 +512,7 @@ void SCH_FIND_COLLECTOR::Collect( SCH_FIND_REPLACE_DATA& aFindReplaceData,
Empty(); // empty the collection just in case Empty(); // empty the collection just in case
m_data.clear(); m_data.clear();
m_foundIndex = 0; m_foundIndex = 0;
m_forceSearch = false; SetForceSearch( false );
if( aSheetPath ) if( aSheetPath )
{ {
......
...@@ -231,11 +231,15 @@ class SCH_FIND_COLLECTOR : public COLLECTOR ...@@ -231,11 +231,15 @@ class SCH_FIND_COLLECTOR : public COLLECTOR
SCH_SHEET_PATH* m_sheetPath; SCH_SHEET_PATH* m_sheetPath;
/// The current found item list index. /// The current found item list index.
int m_foundIndex; int m_foundIndex;
/// A flag to indicate that the schemtic has been modified and a new search must be /// A flag to indicate that the schemtic has been modified and a new search must be
/// performed even if the search criteria hasn't changed. /// performed even if the search criteria hasn't changed.
bool m_forceSearch; bool m_forceSearch;
/// last known library change hash, used to detect library changes which
/// should trigger cache obsolescence.
int m_lib_hash;
/** /**
* Function dump * Function dump
...@@ -254,7 +258,7 @@ public: ...@@ -254,7 +258,7 @@ public:
{ {
SetScanTypes( aScanTypes ); SetScanTypes( aScanTypes );
m_foundIndex = 0; m_foundIndex = 0;
m_forceSearch = false; SetForceSearch( false );
m_sheetPath = NULL; m_sheetPath = NULL;
} }
...@@ -265,7 +269,10 @@ public: ...@@ -265,7 +269,10 @@ public:
m_data.clear(); m_data.clear();
} }
void SetForceSearch() { m_forceSearch = true; } void SetForceSearch( bool doSearch = true ) { m_forceSearch = doSearch; }
int GetLibHash() const { return m_lib_hash; }
void SetLibHash( int aHash ) { m_lib_hash = aHash; }
/** /**
* Function PassedEnd * Function PassedEnd
...@@ -294,7 +301,7 @@ public: ...@@ -294,7 +301,7 @@ public:
/** /**
* Function IsSearchRequired * Function IsSearchRequired
* checks the current collector state agaianst \a aFindReplaceData to see if a new search * checks the current collector state against \a aFindReplaceData to see if a new search
* needs to be performed to update the collector. * needs to be performed to update the collector.
* *
* @param aFindReplaceData A #SCH_FIND_REPLACE_DATA object containing the search criteria * @param aFindReplaceData A #SCH_FIND_REPLACE_DATA object containing the search criteria
...@@ -302,7 +309,7 @@ public: ...@@ -302,7 +309,7 @@ public:
* @return True if \a aFindReplaceData would require a new search to be performaed or * @return True if \a aFindReplaceData would require a new search to be performaed or
* the force search flag is true. Otherwise, false is returned. * the force search flag is true. Otherwise, false is returned.
*/ */
bool IsSearchRequired( SCH_FIND_REPLACE_DATA& aFindReplaceData ) bool IsSearchRequired( const SCH_FIND_REPLACE_DATA& aFindReplaceData )
{ {
return m_findReplaceData.ChangesCompare( aFindReplaceData ) || m_forceSearch || return m_findReplaceData.ChangesCompare( aFindReplaceData ) || m_forceSearch ||
(m_findReplaceData.IsWrapping() != aFindReplaceData.IsWrapping()); (m_findReplaceData.IsWrapping() != aFindReplaceData.IsWrapping());
......
...@@ -35,6 +35,7 @@ ...@@ -35,6 +35,7 @@
#include <kicad_string.h> #include <kicad_string.h>
#include <eeschema_id.h> #include <eeschema_id.h>
#include <pgm_base.h> #include <pgm_base.h>
#include <kiway.h>
#include <class_drawpanel.h> #include <class_drawpanel.h>
#include <sch_item_struct.h> #include <sch_item_struct.h>
#include <schframe.h> #include <schframe.h>
......
...@@ -719,8 +719,7 @@ void SCH_EDIT_FRAME::OnModify() ...@@ -719,8 +719,7 @@ void SCH_EDIT_FRAME::OnModify()
GetScreen()->SetModify(); GetScreen()->SetModify();
GetScreen()->SetSave(); GetScreen()->SetSave();
if( m_dlgFindReplace == NULL ) m_foundItems.SetForceSearch();
m_foundItems.SetForceSearch();
} }
......
...@@ -734,6 +734,9 @@ public: ...@@ -734,6 +734,9 @@ public:
// General search: // General search:
bool IsSearchCacheObsolete( const SCH_FIND_REPLACE_DATA& aSearchCriteria );
private: private:
/** /**
......
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