Seg. fault when reinitialize geometry with UI commands

Dear Geant4 users,
I have a seg. fault and I can’t figure it out for a few days. The problem is related to UI commands, reinitializing the geometry, and sensitive detectors. if I change the geometry in interactive mode via interface commands, after a few runs, seg. fault may happen in some geometric cases. There is no problem if I don’t reinitialize the geometry. Preinit state user interface commands works fine but the commands executed after /run/initialize have problems.

When I comment out “SetSensitiveDetector(“NuScntLogic”, fNeutrinoSD.Get(), false)” and “SetSensitiveDetector(“PhotonDetLogic”, fPhotonSD.Get(),true)” (shown below). , there is no seg. fault

void NuSDVDetConstruction::ConstructSDs()
{

//---------NeutrinoSD--------------

if(!fNeutrinoSD.Get())
{

NuSDNeutrinoSD *mainSD = new NuSDNeutrinoSD("NeutrinoSD","NeutrinoSDHitCol");       
G4SDManager::GetSDMpointer()->AddNewDetector(mainSD);
fNeutrinoSD.Put(mainSD);

}

SetSensitiveDetector(“NuScntLogic”, fNeutrinoSD.Get(), false);

//---------PhotonSD--------------
if(!fIsOn) { return; }
if(!fPhotonSD.Get())
{

NuSDPhotonSD *photonSD = new NuSDPhotonSD("PhotonSD","PhotonSD_hit_col");
G4SDManager::GetSDMpointer()->AddNewDetector(photonSD); 
fPhotonSD.Put(photonSD); 

}

SetSensitiveDetector(“PhotonDetLogic”, fPhotonSD.Get(),true);

}

G4VPhysicalVolume* NuSDProspectDetConstruction::Construct()
{

if(fPhysWorld) //clean up old geometry
{
fPhysUnitVector.clear();
fPhysOptReadoutUnitVec.clear();
fVisAttributes.clear();

G4GeometryManager::GetInstance()->OpenGeometry();

G4PhysicalVolumeStore::GetInstance()->Clean();
G4LogicalVolumeStore::GetInstance()->Clean();
G4SolidStore::GetInstance()->Clean();
G4LogicalSkinSurface::CleanSurfaceTable();
G4LogicalBorderSurface::CleanSurfaceTable();

}

DefineMaterials();

//set-up full detector step by step
DefineDetCompDimensions();
DefineSolidsAndLogics();
ConstructSingleDetUnit();
ConstructMatrixDet();
SetReflectorSurface();
SetVisProp();
PlaceDetInWorld();

return fPhysWorld;

}

backtrace are shown below:

#5 0x00007f3cf261740d in __dynamic_cast () at /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#6 0x00007f3cf4d2fedf in G4VUserDetectorConstruction::SetSensitiveDetector(G4LogicalVolume*, G4VSensitiveDetector*) () at /home/mustafa/Downloads/Geant4/geant4.10.06.p01-install/lib/libG4run.so
#7 0x00007f3cf4d30fbd in G4VUserDetectorConstruction::SetSensitiveDetector(G4String const&, G4VSensitiveDetector*, bool) () at /home/mustafa/Downloads/Geant4/geant4.10.06.p01-install/lib/libG4run.so
#8 0x000055e5e90b25de in NuSDVDetConstruction::ConstructSDs() (this=0x55e5e9d31740) at /home/mustafa/Desktop/Nu/NuSD/src/NuSDVDetConstruction.cc:207
#9 0x000055e5e90acc7a in NuSDProspectDetConstruction::ConstructSDandField() (this=0x55e5e9d31740) at /home/mustafa/Desktop/Nu/NuSD/src/NuSDProspectDetConstruction.cc:148
#10 0x00007f3cf4d0ff97 in G4WorkerRunManager::InitializeGeometry() () at /home/mustafa/Downloads/Geant4/geant4.10.06.p01-install/lib/libG4run.so
#11 0x00007f3cf4d00ef1 in G4RunManager::Initialize() () at /home/mustafa/Downloads/Geant4/geant4.10.06.p01-install/lib/libG4run.so
#12 0x00007f3cf4d01c48 in G4RunManager::ConfirmBeamOnCondition() () at /home/mustafa/Downloads/Geant4/geant4.10.06.p01-install/lib/libG4run.so
#13 0x00007f3cf4d00b65 in G4RunManager::BeamOn(int, char const*, int) () at /home/mustafa/Downloads/Geant4/geant4.10.06.p01-install/lib/libG4run.so
#14 0x00007f3cf4d1578b in G4WorkerRunManager::DoWork() () at /home/mustafa/Downloads/Geant4/geant4.10.06.p01-install/lib/libG4run.so
#15 0x00007f3cf4d1d8de in G4MTRunManagerKernel::StartThread(G4WorkerThread*) () at /home/mustafa/Downloads/Geant4/geant4.10.06.p01-install/lib/libG4run.so
#16 0x00007f3cf26436df in () at /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#17 0x00007f3ceabec6db in start_thread (arg=0x7f3ccee1d700) at pthread_create.c:463
#18 0x00007f3cf1d0071f in clone () at …/sysdeps/unix/sysv/linux/x86_64/clone.S:95

–stepping in gdb----

Thread 6 “NuSD” received signal SIGSEGV, Segmentation fault.
0x00007ffff312c40d in __dynamic_cast () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
(gdb) f 207
#0 0x0000000000000000 in ?? ()
(gdb) step
Single stepping until exit from function __dynamic_cast,
which has no line number information.
0x00007ffff6579420 in sighandler(int) () from /home/mustafa/Downloads/root/root_v6.20.00.source/root-6.20.00-build/lib/libCore.so
(gdb) step
Single stepping until exit from function _ZL10sighandleri,
which has no line number information.
0x00007ffff657fa10 in SigHandler(ESignals) () from /home/mustafa/Downloads/root/root_v6.20.00.source/root-6.20.00-build/lib/libCore.so
(gdb) step
Single stepping until exit from function _ZL10SigHandler8ESignals,
which has no line number information.
0x00007ffff657f7e0 in TUnixSystem::DispatchSignals(ESignals) ()
from /home/mustafa/Downloads/root/root_v6.20.00.source/root-6.20.00-build/lib/libCore.so
(gdb) step
Single stepping until exit from function _ZN11TUnixSystem15DispatchSignalsE8ESignals,
which has no line number information.

*** Break *** segmentation violation
__GI_exit (status=139) at exit.c:139
139 exit.c: No such file or directory.