diff --git a/eeschema/sim/ngspice.cpp b/eeschema/sim/ngspice.cpp index 8916b7c63d..3ba4b97662 100644 --- a/eeschema/sim/ngspice.cpp +++ b/eeschema/sim/ngspice.cpp @@ -50,12 +50,6 @@ NGSPICE::~NGSPICE() void NGSPICE::Init() { - if( m_error ) - { - delete m_dll; - init_dll(); - } - Command( "reset" ); } @@ -247,6 +241,7 @@ bool NGSPICE::IsRunning() bool NGSPICE::Command( const string& aCmd ) { LOCALE_IO c_locale; // ngspice works correctly only with C locale + validate(); m_ngSpice_Command( (char*) aCmd.c_str() ); return true; } @@ -454,13 +449,24 @@ int NGSPICE::cbBGThreadRunning( bool is_running, int id, void* user ) int NGSPICE::cbControlledExit( int status, bool immediate, bool exit_upon_quit, int id, void* user ) { // Something went wrong, reload the dll - //NGSPICE* sim = reinterpret_cast( user ); - //sim->m_initialized = false; - //printf("stat %d immed %d quit %d\n", status, !!immediate, !!exit_upon_quit); + NGSPICE* sim = reinterpret_cast( user ); + sim->m_error = true; return 0; } + +void NGSPICE::validate() +{ + if( m_error ) + { + delete m_dll; + m_initialized = false; + init_dll(); + } +} + + const std::string NGSPICE::GetNetlist() const { return m_netlist; diff --git a/eeschema/sim/ngspice.h b/eeschema/sim/ngspice.h index 33d28ca3c2..c3d80f4fff 100644 --- a/eeschema/sim/ngspice.h +++ b/eeschema/sim/ngspice.h @@ -119,9 +119,10 @@ private: static int cbBGThreadRunning( bool is_running, int id, void* user ); static int cbControlledExit( int status, bool immediate, bool exit_upon_quit, int id, void* user ); - void dump(); + // Assures ngspice is in a valid state and reinitializes it if need be + void validate(); - ///> Error flag, meaning ngspice needs to be reloaded + ///> Error flag indicating that ngspice needs to be reloaded bool m_error; ///> NGspice should be initialized only once