Problem 525

Summary: Segmentation fault when adding same element twice to a material
Product: Geant4 Reporter: gorfine
Component: materialsAssignee: kurasige
Status: RESOLVED FIXED    
Severity: minor    
Priority: P2    
Version: 5.2   
Hardware: PC   
OS: Linux   

Description gorfine 2003-09-02 03:50:31 CEST
When the same element (ie a pointer to the same G4Element object) is added more
than once to a material I get a segmentation fault.

This is not something I need to be able to do but either proper treatment or a
warning message would be good.

I am using geant4-05-02. The problem was not present in earlier versions of
geant. (eg I tried geant4-05-00-patch-01 which worked OK).

I was able to reproduce the problem using a modified version of
ExN01DetectorConstruction.cc:

Added the following lines:
-----------------------------
  G4int ncomponents;
  G4String symbol;

  // Oxygen
  a = 16.00*g/mole;
  G4Element* elO = new G4Element(name="Oxygen", symbol="O", z=8., a);

  // Hydrogen
  a = 1.00797*g/mole;
  G4Element* elH = new G4Element(name="Hydrogen", symbol="H", z=1., a);


  density = 1.*g/cm3;
  G4Material* testMat = new G4Material(name="TestMat", density, ncomponents = 3);
  testMat->AddElement(elH, 0.5);
  testMat->AddElement(elO, 0.25);
  testMat->AddElement(elO, 0.25); // <-- Adding it twice causes a seg fault.

-----------------------

And referencing the material somewhere, eg

  tracker_log = new G4LogicalVolume(tracker_tube,testMat,"tracker_log",0,0,0);

I get a segmentation fault at some point after detector construction.

A print out of the materials looks normal:

 Material:  TestMat     density:  1.000 g/cm3   temperature: 273.15 K  pressure:
  1.00 atm  RadLength:  44.378 cm
   --->  Element: Hydrogen  H   Z =  1.0   N =   1.0   A =   1.01 g/mole
fractionMass:  50.00 %  Abundance  94.07 %
   --->  Element:   Oxygen  O   Z =  8.0   N =  16.0   A =  16.00 g/mole
fractionMass:  50.00 %  Abundance   5.93 %


The stack trace is:

Program received signal SIGSEGV, Segmentation fault.
0x401f0d67 in G4VRangeToEnergyConverter::RangeLogSimpson(std::vector<G4Element*,
std::allocator<G4Element*> > const*, double const*, double, double, double, int)
() from
/data/atlas/offline/6.5.0/sw/geant4/releases/specific/redhat73/gcc-3.2/geant4.5.2/lib/Linux-g++/libG4particles.so
(gdb) where
#0  0x401f0d67 in
G4VRangeToEnergyConverter::RangeLogSimpson(std::vector<G4Element*,
std::allocator<G4Element*> > const*, double const*, double, double, double, int)
() from
/data/atlas/offline/6.5.0/sw/geant4/releases/specific/redhat73/gcc-3.2/geant4.5.2/lib/Linux-g++/libG4particles.so
#1  0x401e9393 in G4RToEConvForElectron::BuildRangeVector(G4Material const*,
double, double, G4PhysicsLogVector*) ()
   from
/data/atlas/offline/6.5.0/sw/geant4/releases/specific/redhat73/gcc-3.2/geant4.5.2/lib/Linux-g++/libG4particles.so
#2  0x401f0904 in G4VRangeToEnergyConverter::Convert(double, G4Material const*) ()
   from
/data/atlas/offline/6.5.0/sw/geant4/releases/specific/redhat73/gcc-3.2/geant4.5.2/lib/Linux-g++/libG4particles.so
#3  0x401e21bd in G4ProductionCutsTable::UpdateCoupleTable() ()
   from
/data/atlas/offline/6.5.0/sw/geant4/releases/specific/redhat73/gcc-3.2/geant4.5.2/lib/Linux-g++/libG4particles.so
#4  0x400533b2 in G4RunManager::BuildPhysicsTables() ()
   from
/data/atlas/offline/6.5.0/sw/geant4/releases/specific/redhat73/gcc-3.2/geant4.5.2/lib/Linux-g++/libG4run.so
#5  0x400525a7 in G4RunManager::RunInitialization() ()
   from
/data/atlas/offline/6.5.0/sw/geant4/releases/specific/redhat73/gcc-3.2/geant4.5.2/lib/Linux-g++/libG4run.so
#6  0x400522c5 in G4RunManager::BeamOn(int, char const*, int) ()
   from
/data/atlas/offline/6.5.0/sw/geant4/releases/specific/redhat73/gcc-3.2/geant4.5.2/lib/Linux-g++/libG4run.so
#7  0x0804e356 in main () at ../src/exampleN01.cc:68
#8  0x418311c4 in __libc_start_main () from /lib/libc.so.6
Comment 1 kurasige 2003-11-07 23:50:59 CET
*** Bug 551 has been marked as a duplicate of this bug. ***
*** 'kurasige@phys.sci.kobe-u.ac.jp' will be responsible for bug 551. ***
Comment 2 kurasige 2003-11-07 23:50:59 CET
*** Bug 551 has been marked as a duplicate of this bug. ***
*** 'kurasige@phys.sci.kobe-u.ac.jp' will be responsible for bug 551. ***