Problem 1984

Summary: Crash when exporting geometry with a null material
Product: Geant4 Reporter: mstoeckl
Component: persistency/gdmlAssignee: Witold.Pokorski
Status: RESOLVED FIXED    
Severity: minor    
Priority: P4    
Version: 10.3   
Hardware: All   
OS: All   

Description mstoeckl 2017-06-23 20:52:20 CEST
Parallel worlds by default do not have materials assigned. As a result, when
you export a parallel world geometry to GDML, the writer crashes in the GenerateName function when it is called with a null material. 

[The easy fix; return a placeholder name when the input to GenerateName is null.]
Comment 1 Witold.Pokorski 2017-10-02 15:53:18 CEST
Hi,

sorry for the delay in handling it.

I have modified G4GDMLWriteStructure to handle the null pointer to material.
Could you please test the diff below?

Cheers,
Witek



Index: src/G4GDMLWriteStructure.cc
===================================================================
--- src/G4GDMLWriteStructure.cc	(revision 106330)
+++ src/G4GDMLWriteStructure.cc	(working copy)
@@ -448,12 +448,18 @@
 
    const G4String name
      = GenerateName(tmplv->GetName(), tmplv);
-   const G4String materialref
-         = GenerateName(volumePtr->GetMaterial()->GetName(),
-                        volumePtr->GetMaterial());
+
+   G4String materialref = "NULL";
+     
+   if(volumePtr->GetMaterial())
+     {
+       materialref = GenerateName(volumePtr->GetMaterial()->GetName(),
+				  volumePtr->GetMaterial());
+     }
+   
    const G4String solidref
-         = GenerateName(solidPtr->GetName(),solidPtr);
-
+     = GenerateName(solidPtr->GetName(),solidPtr);
+       
    xercesc::DOMElement* volumeElement = NewElement("volume");
    volumeElement->setAttributeNode(NewAttribute("name",name));
    xercesc::DOMElement* materialrefElement = NewElement("materialref");