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:
* @return True if \a aFindReplaceData would result in a search and/or replace change,
* otherwise false.
*/
bool ChangesCompare( SCH_FIND_REPLACE_DATA& aFindReplaceData )
bool ChangesCompare( const SCH_FIND_REPLACE_DATA& aFindReplaceData )
{
return ( (GetFindString() != aFindReplaceData.GetFindString())
|| (GetCompareFlags() != aFindReplaceData.GetCompareFlags()) );
......
......@@ -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 )
{
static wxPoint itemPosition; // the actual position of the matched item.
......@@ -303,7 +322,7 @@ void SCH_EDIT_FRAME::OnFindSchematicItem( wxFindDialogEvent& aEvent )
if( m_foundItems.GetCount() == 0 )
return;
}
else if( m_foundItems.IsSearchRequired( searchCriteria ) )
else if( IsSearchCacheObsolete( searchCriteria ) )
{
if( aEvent.GetFlags() & FR_CURRENT_SHEET_ONLY && g_RootSheet->CountSheets() > 1 )
{
......
......@@ -467,7 +467,7 @@ bool SCH_FIND_COLLECTOR::ReplaceItem( SCH_SHEET_PATH* aSheetPath )
bool replaced = item->Replace( m_findReplaceData, aSheetPath );
if( replaced )
m_forceSearch = true;
SetForceSearch();
return replaced;
}
......@@ -512,7 +512,7 @@ void SCH_FIND_COLLECTOR::Collect( SCH_FIND_REPLACE_DATA& aFindReplaceData,
Empty(); // empty the collection just in case
m_data.clear();
m_foundIndex = 0;
m_forceSearch = false;
SetForceSearch( false );
if( aSheetPath )
{
......
......@@ -231,11 +231,15 @@ class SCH_FIND_COLLECTOR : public COLLECTOR
SCH_SHEET_PATH* m_sheetPath;
/// 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
/// 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
......@@ -254,7 +258,7 @@ public:
{
SetScanTypes( aScanTypes );
m_foundIndex = 0;
m_forceSearch = false;
SetForceSearch( false );
m_sheetPath = NULL;
}
......@@ -265,7 +269,10 @@ public:
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
......@@ -294,7 +301,7 @@ public:
/**
* 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.
*
* @param aFindReplaceData A #SCH_FIND_REPLACE_DATA object containing the search criteria
......@@ -302,7 +309,7 @@ public:
* @return True if \a aFindReplaceData would require a new search to be performaed or
* 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 ||
(m_findReplaceData.IsWrapping() != aFindReplaceData.IsWrapping());
......
......@@ -35,6 +35,7 @@
#include <kicad_string.h>
#include <eeschema_id.h>
#include <pgm_base.h>
#include <kiway.h>
#include <class_drawpanel.h>
#include <sch_item_struct.h>
#include <schframe.h>
......
......@@ -719,8 +719,7 @@ void SCH_EDIT_FRAME::OnModify()
GetScreen()->SetModify();
GetScreen()->SetSave();
if( m_dlgFindReplace == NULL )
m_foundItems.SetForceSearch();
m_foundItems.SetForceSearch();
}
......
......@@ -734,6 +734,9 @@ public:
// General search:
bool IsSearchCacheObsolete( const SCH_FIND_REPLACE_DATA& aSearchCriteria );
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