G4Exception::DumpTrackInfo() will segfault without real tracks

Geant4 Version: 10.7.4 (but present in 11-Series)
Operating System: RHEL8, MacOS 10.15.7
Compiler/Version: GCC 12.2.0, Apple Clang 12.0.0
CMake Version: 3.24.3, 3.15.2


I’ve discovered that calling G4Exception with FatalException causes a segfault if we use /run/beamOn without a primary generator. We have a Digitizer class which can operate without hits (to generate a detector response with test signals), so this should be a legitimate configuration.

However, we get a segfault in G4ExceptionHandler::DumpTrackInfo() at the line

    if(theStep->GetPreStepPoint()->GetPhysicalVolume())

and internally within GetPhysicalVolume(), at

G4ReferenceCountedHandle<X>::operator->()

There is a test for theStep being not null at the beginning of DumpTrackInfo(), but unfortunately the step is always not null, but may be incomplete! The G4SteppingManager constructor does this:

  // Construct simple 'has-a' related objects
  fStep = new G4Step();
  fSecondary = fStep->NewSecondaryVector();
  fPreStepPoint = fStep->GetPreStepPoint();
  fPostStepPoint = fStep->GetPostStepPoint();

So whether or not there is actual tracking, G4SteppingManager::fStep is not null, but won’t have valid touchables internally.

We’re using Geant4 10.7.4 in our experiment, but I’ve reviewed the classes in G4 11.2.1 and the issues are still present. We will probably institute a workaround, but I wanted to pass this on to both other users and the G4 developers.