Spice simulator: reload ngSpice dll on error

ngSpice frequently ends up a simulation with an error:
"Error: ngspice.dll cannot recover and awaits to be detached"
The only way forward is to reload the shared library and
reinitialize ngSpice.

Fixes: lp:1753101
* https://bugs.launchpad.net/kicad/+bug/1753101
This commit is contained in:
Maciej Suminski 2018-03-21 17:22:56 +01:00
parent 61e42ba392
commit bad462a228
2 changed files with 18 additions and 11 deletions

View File

@ -50,12 +50,6 @@ NGSPICE::~NGSPICE()
void NGSPICE::Init() void NGSPICE::Init()
{ {
if( m_error )
{
delete m_dll;
init_dll();
}
Command( "reset" ); Command( "reset" );
} }
@ -247,6 +241,7 @@ bool NGSPICE::IsRunning()
bool NGSPICE::Command( const string& aCmd ) bool NGSPICE::Command( const string& aCmd )
{ {
LOCALE_IO c_locale; // ngspice works correctly only with C locale LOCALE_IO c_locale; // ngspice works correctly only with C locale
validate();
m_ngSpice_Command( (char*) aCmd.c_str() ); m_ngSpice_Command( (char*) aCmd.c_str() );
return true; 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 ) int NGSPICE::cbControlledExit( int status, bool immediate, bool exit_upon_quit, int id, void* user )
{ {
// Something went wrong, reload the dll // Something went wrong, reload the dll
//NGSPICE* sim = reinterpret_cast<NGSPICE*>( user ); NGSPICE* sim = reinterpret_cast<NGSPICE*>( user );
//sim->m_initialized = false; sim->m_error = true;
//printf("stat %d immed %d quit %d\n", status, !!immediate, !!exit_upon_quit);
return 0; return 0;
} }
void NGSPICE::validate()
{
if( m_error )
{
delete m_dll;
m_initialized = false;
init_dll();
}
}
const std::string NGSPICE::GetNetlist() const const std::string NGSPICE::GetNetlist() const
{ {
return m_netlist; return m_netlist;

View File

@ -119,9 +119,10 @@ private:
static int cbBGThreadRunning( bool is_running, int id, void* user ); 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 ); 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; bool m_error;
///> NGspice should be initialized only once ///> NGspice should be initialized only once