From d869771f04ddf18d099a5e6031890ead068190a6 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Thu, 11 Aug 2016 14:41:48 +0200 Subject: [PATCH] Display an error message if ngspice DLL is missing --- eeschema/sim/ngspice.cpp | 4 +++- eeschema/sim/sim_plot_frame.cpp | 4 ++++ eeschema/sim/spice_simulator.cpp | 13 ++++++++++++- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/eeschema/sim/ngspice.cpp b/eeschema/sim/ngspice.cpp index de0b68a0d7..f05d17a9dd 100644 --- a/eeschema/sim/ngspice.cpp +++ b/eeschema/sim/ngspice.cpp @@ -39,7 +39,9 @@ NGSPICE::NGSPICE() #else m_dll = new wxDynamicLibrary( "libngspice.so" ); #endif - assert( m_dll ); + + if( !m_dll || !m_dll->IsLoaded() ) + throw std::runtime_error( "Missing ngspice shared library" ); // Obtain function pointers m_ngSpice_Init = (ngSpice_Init) m_dll->GetSymbol( "ngSpice_Init" ); diff --git a/eeschema/sim/sim_plot_frame.cpp b/eeschema/sim/sim_plot_frame.cpp index 174ae3403f..be57e88ae8 100644 --- a/eeschema/sim/sim_plot_frame.cpp +++ b/eeschema/sim/sim_plot_frame.cpp @@ -120,6 +120,10 @@ void SIM_PLOT_FRAME::StartSimulation() /// @todo is it necessary to recreate simulator every time? m_simulator.reset( SPICE_SIMULATOR::CreateInstance( "ngspice" ) ); + + if( !m_simulator ) + return; + m_simulator->SetReporter( new SIM_THREAD_REPORTER( this ) ); m_simulator->Init(); m_simulator->LoadNetlist( formatter.GetString() ); diff --git a/eeschema/sim/spice_simulator.cpp b/eeschema/sim/spice_simulator.cpp index f888c31a45..22bab368bd 100644 --- a/eeschema/sim/spice_simulator.cpp +++ b/eeschema/sim/spice_simulator.cpp @@ -24,8 +24,19 @@ #include "ngspice.h" +#include + SPICE_SIMULATOR* SPICE_SIMULATOR::CreateInstance( const std::string& ) { - return new NGSPICE; + try + { + return new NGSPICE; + } + catch( std::exception& e ) + { + DisplayError( NULL, e.what() ); + } + + return NULL; }