Segmentatoin Fault - geometry closed/delete

I am running into the following error when the photon produced in the scintillator tries to escape the world.

> ===========================================================
> There was a crash.
> This is the entire stack trace of all threads:
> ===========================================================
> #0  0x00007fee82c85dbc in waitpid () from /usr/lib64/libc.so.6
> #1  0x00007fee82c08cc2 in do_system () from /usr/lib64/libc.so.6
> #2  0x00007fee8e6d3ba9 in TUnixSystem::StackTrace() () from /scif/apps/root/lib/libCore.so
> #3  0x00007fee8e6d58ac in TUnixSystem::DispatchSignals(ESignals) () from /scif/apps/root/lib/libCore.so
> #4  <signal handler called>
> #5  0x00007fee8377baad in std::string::compare(char const*) const () from /usr/lib64/libstdc++.so.6
> #6  0x00000000004187ec in UCNBSteppingAction::UserSteppingAction(G4Step const*) ()
> #7  0x00007fee8768cb42 in G4SteppingManager::Stepping() () from /scif/apps/geant4/lib64/libG4tracking.so
> #8  0x00007fee8769696d in G4TrackingManager::ProcessOneTrack(G4Track*) () from /scif/apps/geant4/lib64/libG4tracking.so
> #9  0x00007fee878cce01 in G4EventManager::DoProcessing(G4Event*) () from /scif/apps/geant4/lib64/libG4event.so
> #10 0x00007fee87b60057 in G4RunManager::ProcessOneEvent(int) () from /scif/apps/geant4/lib64/libG4run.so
> #11 0x00007fee87b592c3 in G4RunManager::DoEventLoop(int, char const*, int) () from /scif/apps/geant4/lib64/libG4run.so
> #12 0x00007fee87b5908e in G4RunManager::BeamOn(int, char const*, int) () from /scif/apps/geant4/lib64/libG4run.so
> #13 0x00007fee87b72878 in G4RunMessenger::SetNewValue(G4UIcommand*, G4String) () from /scif/apps/geant4/lib64/libG4run.so
> #14 0x00007fee83f9b3ff in G4UIcommand::DoIt(G4String) () from /scif/apps/geant4/lib64/libG4intercoms.so
> #15 0x00007fee83fb8379 in G4UImanager::ApplyCommand(char const*) () from /scif/apps/geant4/lib64/libG4intercoms.so
> #16 0x00007fee83f88947 in G4UIbatch::ExecCommand(G4String const&) () from /scif/apps/geant4/lib64/libG4intercoms.so
> #17 0x00007fee83f8a00b in G4UIbatch::SessionStart() () from /scif/apps/geant4/lib64/libG4intercoms.so
> #18 0x00007fee83faf823 in G4UImanager::ExecuteMacroFile(char const*) () from /scif/apps/geant4/lib64/libG4intercoms.so
> #19 0x00007fee83fa3c2a in G4UIcontrolMessenger::SetNewValue(G4UIcommand*, G4String) () from /scif/apps/geant4/lib64/libG4intercoms.so
> #20 0x00007fee83f9b3ff in G4UIcommand::DoIt(G4String) () from /scif/apps/geant4/lib64/libG4intercoms.so
> #21 0x00007fee83fb8379 in G4UImanager::ApplyCommand(char const*) () from /scif/apps/geant4/lib64/libG4intercoms.so
> #22 0x000000000040b6ec in main ()
> ===========================================================
> 
> 
> WARNING - Attempt to delete the physical volume store while geometry closed !
> WARNING - Attempt to delete the logical volume store while geometry closed !
> WARNING - Attempt to delete the solid store while geometry closed !
> WARNING - Attempt to delete the region store while geometry closed !
> 

This happens when i add the following piece of code in Stepping Action

 if(fStep->GetPostStepPoint()->GetPhysicalVolume()->GetName() == "Silicon1" && fStep->GetPreStepPoint()->GetPhysicalVolume()->GetName() == "Dead1"){
        G4cout<<"Entering detector 1 "<<G4endl;
        G4ThreeVector pIncidentDet1 = fStep->GetPostStepPoint()->GetMomentumDirection();
        G4double pInDet1x = pIncidentDet1.x();
        G4double pInDet1y = pIncidentDet1.y();
        G4double pInDet1z = pIncidentDet1.z();
        G4cout <<" pinx -- befre run ---: "<<pInDet1x<<G4endl;
        UCNBAnalysisManager::getInstance()->px_in_det1 = pInDet1x;
        }

Any direction you could point to !

The segfault is before the “geometry closed” messages, so it’s due to something in your code.

In the code you posted, you are dereferencing pointers without testing whether they are null or not. For example,

Do you know that GetPostStepPoint() always returns a valid pointer? Does GetPhysicalVolume() always return a valid pointer? If not, then in each case you should test for a null return value before doing the next step in that chain.

Hello,

when a particle went out of the world, there is no valid pointer to physics volume post step and the crash happens in GetName(). Such pointer does not exist.

VI

Problem trace and printouts about geometry close/delete are a bit misleading.

Thank you for the insight.
I tried checking by implementing the following :

if (fStep->GetPostStepPoint()->GetPhysicalVolume()){

the code hasn’t crashed yet which i understand because earlier it might have been returning a null pointer. However, there are several if conditions like the block i mentioned above. Would you recommend checking it at every point?

Thank you for the insight!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.