From: <ng...@at...> - 2022-03-05 14:19:49
|
Dear developers, The attached C++ source demonstrates a curious segfault. The code calls ngSpice_Init, runs a circuit sim, then calls remcirc to delete the circuit, then calls ngSpice_Init again and runs another circuit, at which point there is a crash. Removing either the remcirc command or the second ngSpice_Init call fixes it. I would hope that calling ngSpice_Init again would reset ngspice back to its default state and set the new callbacks, but apparently it leaves some old memory around? Alternatively if ngSpice_Init is not supposed to be called again, I would expect there to be a shutdown function available that cleans up, allowing ngSpice_Init to be called once more. It seems KiCad avoids this problem by loading libngspice.so at runtime using dlopen() each time a simulation is run, which implicitly resets ngspice's internal state. It would be good if there were a way to reset the state in the case of compile-time linking as well (if I missed an existing way to do this, I'd be pleased to find out!). Cheers, Sean Leavey |