| Summary: | G4GDMLWriteMaterials::PropertyWrite passes null pointer, segfaults | ||
|---|---|---|---|
| Product: | Geant4 | Reporter: | Wouter Deconinck <wdconinc> |
| Component: | persistency/gdml | Assignee: | Gabriele Cosmo <Gabriele.Cosmo> |
| Status: | RESOLVED FIXED | ||
| Severity: | normal | CC: | gum |
| Priority: | P5 | ||
| Version: | 9.4 | ||
| Hardware: | All | ||
| OS: | All | ||
| Attachments: |
Work-around for null pointers
Minimal example |
||
Created attachment 117 [details] Minimal example This is a minimal example that demonstrates the problem. Expected results: Runs without problems, creates test.gdml file. Actual results: 15:55:07 wdconinc@fhelena ~/qweak/QwGeant4/trunk $ bin/Linux-g++/test G4GDML: Writing 'test.gdml'... G4GDML: Writing definitions... G4GDML: Writing materials... G4GDML: Writing solids... G4GDML: Writing structure... G4GDML: Writing setup... *** Break *** segmentation violation Results with patch applied: 15:46:14 wdconinc@fhelena ~/qweak/QwGeant4/trunk $ bin/Linux-g++/test G4GDML: Writing 'test.gdml'... G4GDML: Writing definitions... G4GDML: Writing materials... G4GDML: Writing solids... G4GDML: Writing structure... G4GDML: Writing setup... G4GDML: null pointer for material property RAYLEIGH of material Air G4GDML: Writing surfaces... G4GDML: Writing 'test.gdml' done ! Actual results (in debugger): 15:56:13 wdconinc@fhelena ~/qweak/QwGeant4/trunk $ gdb -ex run --args bin/Linux-g++/test GNU gdb (Ubuntu/Linaro 7.2-1ubuntu11) 7.2 Copyright (C) 2010 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "i686-linux-gnu". For bug reporting instructions, please see: <http://www.gnu.org/software/gdb/bugs/>... Reading symbols from /data/workspace/QwGeant4/bin/Linux-g++/test...done. Starting program: /data/workspace/QwGeant4/bin/Linux-g++/test [Thread debugging using libthread_db enabled] G4GDML: Writing 'test.gdml'... G4GDML: Writing definitions... G4GDML: Writing materials... G4GDML: Writing solids... G4GDML: Writing structure... G4GDML: Writing setup... Program received signal SIGSEGV, Segmentation fault. 0x0059ba1c in G4MaterialPropertyVector::Entries (this=0x0) at /usr/local/src/geant4/geant4.9.4.p01-local/source/materials/include/G4MaterialPropertyVector.icc:65 65 return NumEntries; (gdb) bt #0 0x0059ba1c in G4MaterialPropertyVector::Entries (this=0x0) at /usr/local/src/geant4/geant4.9.4.p01-local/source/materials/include/G4MaterialPropertyVector.icc:65 #1 0x0059add4 in G4GDMLWriteMaterials::PropertyVectorWrite (this=0x824e920, key=..., pvec=0x0) at src/G4GDMLWriteMaterials.cc:203 #2 0x0059b123 in G4GDMLWriteMaterials::PropertyWrite (this=0x824e920, matElement=0x82b3f48, mat=0x823ebb0) at src/G4GDMLWriteMaterials.cc:233 #3 0x0059a7a0 in G4GDMLWriteMaterials::MaterialWrite (this=0x824e920, materialPtr=0x823ebb0) at src/G4GDMLWriteMaterials.cc:154 #4 0x0059b78f in G4GDMLWriteMaterials::AddMaterial (this=0x824e920, materialPtr=0x823ebb0) at src/G4GDMLWriteMaterials.cc:288 #5 0x005b3163 in G4GDMLWriteStructure::TraverseVolumeTree (this=0x824e920, volumePtr=0x82481c0, depth=0) at src/G4GDMLWriteStructure.cc:504 #6 0x00594f89 in G4GDMLWrite::Write (this=0x824e920, fname=..., logvol=0x82481c0, setSchemaLocation=..., depth=0, refs=true) at src/G4GDMLWrite.cc:195 #7 0x0804f685 in G4GDMLParser::Write (this=0xbfffe2e4, filename=..., pvol=0x82483d0, refs=true, schemaLocation=...) at /data/local/src/geant4/geant4.9.3.p02-local/source/persistency/gdml/include/G4GDMLParser.icc:70 #8 0x0804e883 in main () at test.cc:43 (gdb) System: Linux fhelena 2.6.38-9-generic #43-Ubuntu SMP Thu Apr 28 15:25:15 UTC 2011 i686 i686 i386 GNU/Linux gcc (Ubuntu/Linaro 4.5.2-8ubuntu4) 4.5.2 geant4.9.4.p01 (installed from source) Thanks for the report. The fix will be included in the next patch or release! The underlying issue is that a G4PhysicsTable must be booked with all of the existing materials as arguments:
// create a new physics table
thePhysicsTable = new G4PhysicsTable(numOfMaterials);
even if one wants to fill it for just 'DefaultWater'.
I shall look into employing a G4MaterialPropertiesTable instead to hold the RAYLEIGH scattering length for 'DefaultWater' just as it is done for other materials where the scattering length is user defined.
> In particular (in my case) the "RAYLEIGH" property of the material "Air" was > not defined but still ended up in the material's property table with a null > pointer (this apparently happens when you create G4OpRayleigh even when you > don't add it to the process manager). Pondering this issue some more, I don't understand how the G4MaterialPropertiesTable of your material "Air" ended up with a NULL G4MaterialPropertyVector because of the G4OpRayleigh constructor alone. Have you checked, for example, in your EndOfRunAction, that indeed: const G4MaterialTable* theMaterialTable= G4Material::GetMaterialTable(); G4int numOfMaterials = G4Material::GetNumberOfMaterials(); for (G4int i=0 ; i < numOfMaterials; i++) { G4MaterialPropertiesTable *aMaterialPropertiesTable = (*theMaterialTable)[i]->GetMaterialPropertiesTable(); if(aMaterialPropertiesTable){ G4MaterialPropertyVector* AttenuationLengthVector = aMaterialPropertiesTable->GetProperty("RAYLEIGH"); if(AttenuationLengthVector){ if ((*theMaterialTable)[i]->GetName() == "Air") G4cout << "BINGO" << G4endl; } } } Thanks again for reporting this and your help in debugging it is most appreciated! |
Created attachment 116 [details] Work-around for null pointers Cc: processes/optical because might be a problem in G4OpRayleigh. When exporting a GDML file using the G4GDMLparser, it is possible to get a segmentation fault due to undefined material properties. In G4GDMLWriteMaterials::PropertyWrite the iterator mpos over pmap = ptable->GetPropertiesMap() has null in the second field, which it passes to G4GDMLWriteMaterials::PropertyVectorWrite where it is dereferenced in pvec->Entries(). The attached patch works around this problem by skipping null pointers and printing a warning indicating the material and property. In particular (in my case) the "RAYLEIGH" property of the material "Air" was not defined but still ended up in the material's property table with a null pointer (this apparently happens when you create G4OpRayleigh even when you don't add it to the process manager). Marking as normal severity (+1 segfault, -1 rare use case).