Null-pointer dereference in directional Compton splitting with G4EmLivermorePhysics

Hello,

I found a reproducible segmentation fault when using directional secondary splitting for the Compton process.

Geant4 version: 11.4.2 (Also reproduced with 11.4.0)

Operating system: Ubuntu 24.04.3 LTS

Compiler: g++ (Ubuntu 13.3.0-6ubuntu2~24.04.1) 13.3.0

Physics constructor: G4EmLivermorePhysics

Primary particle: gamma

Energy range: 1–100 keV

Here is the biasing configuration used:

RegisterPhysics(new G4EmLivermorePhysics());

auto* parameters = G4EmParameters::Instance();

parameters->SetFluo(true);
parameters->SetAuger(true);
parameters->SetPixe(true);
parameters->SetDeexcitationIgnoreCut(true);

parameters->ActivateSecondaryBiasing(
    "compt", "SampleRegion", 1000, 1*MeV
);

parameters->SetDirectionalSplitting(true);
parameters->SetDirectionalSplittingTarget(targetPosition);
parameters->SetDirectionalSplittingRadius(targetRadius);

With directional splitting disabled, the simulation completes successfully. With directional Compton splitting enabled, it crashes inside G4EmBiasingManager::ApplyDirectionalSplitting(...).

GDB confirms that the temporary secondary vector contains a null pointer at the time of the crash:

kk = 1

k = 176

nsplit = 1000

tmpSecondaries.size() = 2

(gdb) p tmpSecondaries[kk]

$7 = (G4DynamicParticle *) 0x0


The null pointer is then dereferenced when the code evaluates tmpSecondaries[kk]->GetParticleDefinition().

To test a fix, I added a local check for the null pointer inside the ApplyDirectionalSplitting function in the Geant4 source code:

    for (std::size_t kk=0; kk<tmpSecondaries.size(); ++kk) {

        if(tmpSecondaries[kk]==nullptr){

          continue;

        }

        if (tmpSecondaries[kk]->GetParticleDefinition() == theGamma) {

After rebuilding Geant4 11.4.2 with this change, the previously crashing simulation runs successfully with a Compton splitting factor of 1000.

Could you please confirm whether skipping null entries here is the correct fix, or if the null pointer is a symptom of an issue occurring earlier in the tracking process?

Thank you!