Problem 2140 - The release of the static G4AssemblyStore after the static G4PhysicalVolumeStore will result in segmentation fault (core dumped)
Summary: The release of the static G4AssemblyStore after the static G4PhysicalVolumeSt...
Status: RESOLVED FIXED
Alias: None
Product: Geant4
Classification: Unclassified
Component: geometry/volumes (show other problems)
Version: 10.5
Hardware: All Linux
: P4 minor
Assignee: Gabriele Cosmo
URL:
Depends on:
Blocks:
 
Reported: 2019-03-01 09:11 CET by Binbin Qi
Modified: 2019-03-01 15:07 CET (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this problem.
Description Binbin Qi 2019-03-01 09:11:46 CET
A new class G4AssemlyStore has been added to the Geant 4-10.5 in order to release all G4AssemblyVolume objects. The destructor of class G4AssemblyVolume will release all the PhysicalVolumes in this AssemblyVolume. However, all G4VPhysicalVolumes will be released by the destructor of class G4PhysicalVolumeStore at the end of the program. If the destructor of the class G4PhysicalVolumeStore is called before the destructor of the class G4AssemlyStore, then the PhysicalVolume in each existing Assembly will be deleted twice, which will result in a segmentation fault (core dumped).

For example, I use the following code:

     317   //in G4VPhysicalVolume* G02DetectorConstruction::Construct()
     318
     319   G4AssemblyVolume *plateAV1=new G4AssemblyVolume;
     320 
     321   G4Box * experimentalHallBox =
     322       new G4Box("ExpHallBox", fExpHall_x, expHall_y, expHall_z);
     323   G4LogicalVolume * experimentalHallLV =
     324       new G4LogicalVolume(experimentalHallBox, fAir, "ExpHallLV");
     325   G4PVPlacement * experimentalHallPhys =
     326       new G4PVPlacement(0, G4ThreeVector(0.0,0.0,0.0), experimentalHallLV,
     327                         "ExpHallPhys", 0, false, 0);
     328                         

The first G4AssemblyVolume was created before the first G4VPlacement, so the static G4AssemblyStore assemblyStore was created before the static G4PhysicalVolumeStore worldStore, causing the G4AssemblyStore destructor to be called after the G4PhysicalVolumeStore. The result is that at the end of the program, the following error occurs:

     Graphics systems deleted.
     Visualization Manager deleting...
     Segmentation fault (core dumped)

Suggested fix:

  158 G4AssemblyStore* G4AssemblyStore::GetInstance()
  159 {   
  160   if(!fgInstance) G4PhysicalVolumeStore::GetInstance(); //Make sure static 
  161   static G4AssemblyStore assemblyStore;  //G4AssemblyStore is created 
  162   if (!fgInstance)                       //after static G4PhysicalVolumeStore.
  163   { 
  164     fgInstance = &assemblyStore;
  165   }
  166   return fgInstance;
  167 }
Comment 1 Gabriele Cosmo 2019-03-01 09:34:43 CET
Thanks for reporting this case. I will look at it.
Comment 2 Gabriele Cosmo 2019-03-01 15:07:46 CET
This is now fixed in the development version and will be available in a future patch release.