Created attachment 508 [details] Proposed fix While investigating a related issue (https://bugzilla-geant4.kek.jp/show_bug.cgi?id=2082) I bumped into an obscure problem that might cause undesired behaviour. Static variables which require the G4UImanager in their constructors might become instantiated before main starts. The two that got instantiated for me were these: G4PlotManager::fgPlotParameters G4ParticleHPManager::instance I was able to trigger this issue using the Catch2 framework (https://github.com/catchorg/Catch2) and the following source file: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ #include <catch.hpp> #include "G4MTRunManager.hh" TEST_CASE("run 1") { G4MTRunManager man; } TEST_CASE("run 2") { G4MTRunManager man; } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ All the necessary files can be found here: https://gitlab.com/loximann/test-runmanager See the attached file for a patch with the proposed fix. The fix consists of declaring the static instances inside functions, so they are only instantiated when the functions are called for the first time. I avoided renaming and reformatting for clarity, so probably additional changes would be needed to conform to the Geant4 conventions.
The code referred in the patch was reviewed in the development version and will be available in the next release. Thanks for notifying this. Please, note however that as already mentioned in ticket #2082 (https://bugzilla-geant4.kek.jp/show_bug.cgi?id=2082), Geant4 kernel classes are not meant for resetting/re-instantiation in the same application.
Thank you for reviewing the fix :-)