Browse Source

Prevent crash on failure to load ngspice's dll

Fixes https://gitlab.com/kicad/code/kicad/-/issues/20695


(cherry picked from commit f35078cb29)

Co-authored-by: Marek Roszko <mark.roszko@gmail.com>
pull/18/head
Mark Roszko 6 months ago
parent
commit
f3d445efc9
  1. 3
      common/kiway.cpp
  2. 13
      eeschema/eeschema.cpp
  3. 2
      eeschema/sim/ngspice.cpp
  4. 4
      eeschema/sim/simulator_frame.cpp
  5. 12
      eeschema/sim/simulator_frame.h

3
common/kiway.cpp

@ -452,8 +452,9 @@ KIWAY_PLAYER* KIWAY::Player( FRAME_T aFrameType, bool doCreate, wxTopLevelWindow
m_ctl // questionable need, these same flags
// were passed to KIFACE::OnKifaceStart()
);
if( frame )
m_playerFrameId[aFrameType].store( frame->GetId() );
m_playerFrameId[aFrameType].store( frame->GetId() );
return frame;
}
catch( ... )

13
eeschema/eeschema.cpp

@ -191,8 +191,17 @@ static struct IFACE : public KIFACE_BASE, public UNITS_PROVIDER
case FRAME_SIMULATOR:
{
SIMULATOR_FRAME* frame = new SIMULATOR_FRAME( aKiway, aParent );
return frame;
try
{
SIMULATOR_FRAME* frame = new SIMULATOR_FRAME( aKiway, aParent );
return frame;
}
catch( SIMULATOR_INIT_ERR )
{
// catch the init err exception as we don't want it to bubble up
// its going to be some ngspice install issue but we don't want to log that
return nullptr;
}
}
case FRAME_SCH_VIEWER:

2
eeschema/sim/ngspice.cpp

@ -498,7 +498,7 @@ void NGSPICE::init_dll()
#endif
if( !m_dll.IsLoaded() )
throw std::runtime_error( "Missing ngspice shared library" );
throw std::runtime_error( _( "Unable to load ngspice shared library. Please check your install." ).ToStdString() );
m_error = false;

4
eeschema/sim/simulator_frame.cpp

@ -145,7 +145,9 @@ SIMULATOR_FRAME::SIMULATOR_FRAME( KIWAY* aKiway, wxWindow* aParent ) :
mainSizer->Add( m_ui, 1, wxEXPAND, 5 );
m_simulator = SIMULATOR::CreateInstance( "ngspice" );
wxASSERT( m_simulator );
if( !m_simulator )
throw SIMULATOR_INIT_ERR( "Failed to create simulator instance" );
LoadSettings( config() );

12
eeschema/sim/simulator_frame.h

@ -49,6 +49,18 @@ class ACTION_TOOLBAR;
class SPICE_SIMULATOR;
/**
* Simple error container for failure to init the simulation engine
* and ultimately abort the frame construction
*/
class SIMULATOR_INIT_ERR : public std::runtime_error
{
public:
explicit SIMULATOR_INIT_ERR(const std::string& what_arg)
: std::runtime_error(what_arg) {}
};
/**
*
* The SIMULATOR_FRAME holds the main user-interface for running simulations.

Loading…
Cancel
Save