Segmentation fault in Geant4 running

Hi everyone,

I’m running into a segmentation fault when executing my Geant4 application. When I debug with gdb, I get the following backtrace:

Program received signal SIGSEGV, Segmentation fault.
0x00007ffff6f541d0 in G4LogicalVolume::SetSensitiveDetector(G4VSensitiveDetector*)
from /usr/local/lib/libG4geometry.so
(gdb) bt
#0 0x00007ffff6f541d0 in G4LogicalVolume::SetSensitiveDetector(G4VSensitiveDetector*)
from /usr/local/lib/libG4geometry.so
#1 0x000055555555ed27 in MyDetectorConstruction::ConstructSDandField()
#2 0x00007ffff76326c5 in G4RunManager::InitializeGeometry()
from /usr/local/lib/libG4run.so
#3 0x00007ffff7632874 in G4RunManager::Initialize()
from /usr/local/lib/libG4run.so
#4 0x000055555555b0ae in main ()

These are the functions I’m using in my sensitive detector class:

G4bool MySensitiveDetector::ProcessHits(G4Step *aStep, G4TouchableHistory *ROhist) {
    return true;
}

Another one: 

void MyDetectorConstruction::ConstructSDandField()
{
    MySensitiveDetector *sensDet = new MySensitiveDetector("SensitiveDetector");


       logicDetector->SetSensitiveDetector(sensDet);
}

Thak you!
  1. Geant4 Version: 11.2.1
  2. Operating System: Ubuntu 22.04 LTS (64-bit)
  3. Compiler/Version: GCC 11.4.0
  4. CMake Version: 3.22.1

I’m using the latest available versions.


Looks like a null pointer. Check the value of logicDetector.

If you build with CMAKE_BUILD_TYPE=Debug (or RelWithDebInfo if your system supports it) – see Building and Installing from Source — Geant4 Installation Guide 11.3 documentation - gdb will give more information. You can also set breakpoints and interrogate variables.