Problem 466

Summary: crash in G4SteppingManager::InvokeAtRestDoItProcs()
Product: Geant4 Reporter: Witold.Pokorski
Component: trackingAssignee: Takashi.Sasaki
Status: RESOLVED FIXED    
Severity: normal    
Priority: P2    
Version: other   
Hardware: PC   
OS: Linux   

Description Witold.Pokorski 2003-03-14 07:18:45 CET
I have been getting a crash from
G4SteppingManager::InvokeAtRestDoItProcs() in the following
situation:

- the particle for which it is called is a neutron

- the MAXofAtRestLoops=1

- FCurrentProcess becomes then of type fDecay

- lifetime is assigned to be "inf" - I presume that's ok since the
neutron is stable in G4

now, when it goes to
       if(lifeTime < shortestLifeTime ){
         shortestLifeTime = lifeTime;
         fAtRestDoItProcTriggered =  G4int(int(ri));
        }
the condition is not satified because "inf" is not < MAX_DBL and
therefore it leaves the whole "ri" loop without touching
fAtRestDoItProcTriggered

when it reaches then

   (*fSelectedAtRestDoItVector)[fAtRestDoItProcTriggered] = NotForced;

fAtRestDoItProcTriggered has an unitialized value, which results in a
segmentation fault.

So, basically it seems that this code:

   for( size_t ri=0 ; ri < MAXofAtRestLoops ; ri++ ){
     fCurrentProcess = (*fAtRestGetPhysIntVector)[ri];
     if (fCurrentProcess== NULL) {
       (*fSelectedAtRestDoItVector)[ri] = InActivated;
       NofInactiveProc++;
       continue;
     }   // NULL means the process is inactivated by a user on fly.

     lifeTime =
       fCurrentProcess->AtRestGPIL(
                                                     *fTrack,
                                                &fCondition );
     if(fCondition==Forced){
       (*fSelectedAtRestDoItVector)[ri] = Forced;
     }
     else{
       (*fSelectedAtRestDoItVector)[ri] = InActivated;
      if(lifeTime < shortestLifeTime ){
         shortestLifeTime = lifeTime;
         fAtRestDoItProcTriggered =  G4int(int(ri));
       }
     }
   }

cannot deal with cases when lifetime is infinite.

A fix would be to add fAtRestDoItProcTriggered = 0; at the begining of the method.
Comment 1 Takashi.Sasaki 2003-03-23 21:14:59 CET
Please check the processes return DBL_MAX or less for the lifetime.
Comment 2 Hans-Peter.Wellisch 2003-04-01 05:58:59 CEST
Hi Hisaya,

  somehow Takashi forwarded this to me. It seems that Decay is the process in
question. Note also that it would be better to catch such cases at the level of
process management, since it may also happen elsewhere.

Many greetings,

Hans-Peter.
Comment 3 kurasige 2003-04-09 06:34:59 CEST
G4Decay (and some other processes) may return "inf" as a result of GPIL methods.
MeanLifeTime is set to DBL_MAX if the particle is stable. If
theNumberOfInteractionLength is greater than 1, result of GPIL becomes "inf".

If all processes return "inf", fAtRestDoItProcTriggered is not initialized and
crash may happen.
Comment 4 Takashi.Sasaki 2003-04-11 05:13:59 CEST
There was an uninitialised variable in the method. The fix is already committed
in the repository with the tag tracking-V05-00-02.