diff --git a/eeschema/sim/ngspice.cpp b/eeschema/sim/ngspice.cpp index d9990457c6..68820474e0 100644 --- a/eeschema/sim/ngspice.cpp +++ b/eeschema/sim/ngspice.cpp @@ -29,7 +29,6 @@ #include // LOCALE_IO #include #include -#include #include #include @@ -44,7 +43,6 @@ NGSPICE::NGSPICE() NGSPICE::~NGSPICE() { - delete m_dll; } @@ -279,25 +277,28 @@ void NGSPICE::init_dll() LOCALE_IO c_locale; // ngspice works correctly only with C locale + if( m_dll.IsLoaded() ) // enable force reload + m_dll.Unload(); + #ifdef __WINDOWS__ - m_dll = new wxDynamicLibrary( "libngspice-0.dll" ); + m_dll.Load( "libngspice-0.dll" ); #else - m_dll = new wxDynamicLibrary( wxDynamicLibrary::CanonicalizeName( "ngspice" ) ); + m_dll.Load( wxDynamicLibrary::CanonicalizeName( "ngspice" ) ); #endif - if( !m_dll || !m_dll->IsLoaded() ) + if( !m_dll.IsLoaded() ) throw std::runtime_error( "Missing ngspice shared library" ); m_error = false; // Obtain function pointers - m_ngSpice_Init = (ngSpice_Init) m_dll->GetSymbol( "ngSpice_Init" ); - m_ngSpice_Circ = (ngSpice_Circ) m_dll->GetSymbol( "ngSpice_Circ" ); - m_ngSpice_Command = (ngSpice_Command) m_dll->GetSymbol( "ngSpice_Command" ); - m_ngGet_Vec_Info = (ngGet_Vec_Info) m_dll->GetSymbol( "ngGet_Vec_Info" ); - m_ngSpice_AllPlots = (ngSpice_AllPlots) m_dll->GetSymbol( "ngSpice_AllPlots" ); - m_ngSpice_AllVecs = (ngSpice_AllVecs) m_dll->GetSymbol( "ngSpice_AllVecs" ); - m_ngSpice_Running = (ngSpice_Running) m_dll->GetSymbol( "ngSpice_running" ); // it is not a typo + m_ngSpice_Init = (ngSpice_Init) m_dll.GetSymbol( "ngSpice_Init" ); + m_ngSpice_Circ = (ngSpice_Circ) m_dll.GetSymbol( "ngSpice_Circ" ); + m_ngSpice_Command = (ngSpice_Command) m_dll.GetSymbol( "ngSpice_Command" ); + m_ngGet_Vec_Info = (ngGet_Vec_Info) m_dll.GetSymbol( "ngGet_Vec_Info" ); + m_ngSpice_AllPlots = (ngSpice_AllPlots) m_dll.GetSymbol( "ngSpice_AllPlots" ); + m_ngSpice_AllVecs = (ngSpice_AllVecs) m_dll.GetSymbol( "ngSpice_AllVecs" ); + m_ngSpice_Running = (ngSpice_Running) m_dll.GetSymbol( "ngSpice_running" ); // it is not a typo m_ngSpice_Init( &cbSendChar, &cbSendStat, &cbControlledExit, NULL, NULL, &cbBGThreadRunning, this ); @@ -460,7 +461,6 @@ void NGSPICE::validate() { if( m_error ) { - delete m_dll; m_initialized = false; init_dll(); } diff --git a/eeschema/sim/ngspice.h b/eeschema/sim/ngspice.h index c3d80f4fff..5c4058b592 100644 --- a/eeschema/sim/ngspice.h +++ b/eeschema/sim/ngspice.h @@ -27,6 +27,7 @@ #include "spice_simulator.h" +#include #include class wxDynamicLibrary; @@ -101,7 +102,7 @@ private: ngSpice_AllVecs m_ngSpice_AllVecs; ngSpice_Running m_ngSpice_Running; - wxDynamicLibrary* m_dll; + wxDynamicLibrary m_dll; ///> Executes commands from a file bool loadSpinit( const std::string& aFileName );