Browse Source

Fix symbol library viewer crash.

Handle exception in best zoom method when a symbol could not be loaded
from the symbol library table.  This was triggered by an empty symbol
library table but could be triggered by any exception thrown while
loading the symbol.

Fixes lp:1733111

https://bugs.launchpad.net/kicad/+bug/1733111
pull/5/merge
Wayne Stambaugh 8 years ago
parent
commit
8de70f3dd0
  1. 27
      eeschema/viewlib_frame.cpp

27
eeschema/viewlib_frame.cpp

@ -366,6 +366,7 @@ void LIB_VIEW_FRAME::OnUpdateElectricalType( wxUpdateUIEvent& aEvent )
aEvent.Check( GetShowElectricalType() );
}
double LIB_VIEW_FRAME::BestZoom()
{
/* Please, note: wxMSW before version 2.9 seems have
@ -377,7 +378,22 @@ double LIB_VIEW_FRAME::BestZoom()
LIB_PART* part = NULL;
double bestzoom = 16.0; // default value for bestzoom
LIB_ALIAS* alias = Prj().SchSymbolLibTable()->LoadSymbol( m_libraryName, m_entryName );
if( m_libraryName.IsEmpty() || m_entryName.IsEmpty() )
{
SetScrollCenterPosition( wxPoint( 0, 0 ) );
return bestzoom;
}
LIB_ALIAS* alias = nullptr;
try
{
alias = Prj().SchSymbolLibTable()->LoadSymbol( m_libraryName, m_entryName );
}
catch( ... )
{
}
if( alias )
part = alias->GetPart();
@ -394,10 +410,8 @@ double LIB_VIEW_FRAME::BestZoom()
// Reserve a 10% margin around component bounding box.
double margin_scale_factor = 0.8;
double zx =(double) boundingBox.GetWidth() /
( margin_scale_factor * (double)size.x );
double zy = (double) boundingBox.GetHeight() /
( margin_scale_factor * (double)size.y);
double zx =(double) boundingBox.GetWidth() / ( margin_scale_factor * (double)size.x );
double zy = (double) boundingBox.GetHeight() / ( margin_scale_factor * (double)size.y);
// Calculates the best zoom
bestzoom = std::max( zx, zy );
@ -497,7 +511,8 @@ bool LIB_VIEW_FRAME::ReCreateListCmp()
try
{
Prj().SchSymbolLibTable()->EnumerateSymbolLib( m_libraryName, aliasNames, m_listPowerCmpOnly );
Prj().SchSymbolLibTable()->EnumerateSymbolLib( m_libraryName, aliasNames,
m_listPowerCmpOnly );
}
catch( const IO_ERROR& e ) {} // ignore, it is handled below

Loading…
Cancel
Save