Problem 1984 - Crash when exporting geometry with a null material
Summary: Crash when exporting geometry with a null material
Status: RESOLVED FIXED
Alias: None
Product: Geant4
Classification: Unclassified
Component: persistency/gdml (show other problems)
Version: 10.3
Hardware: All All
: P4 minor
Assignee: Witold.Pokorski
URL:
Depends on:
Blocks:
 
Reported: 2017-06-23 20:52 CEST by mstoeckl
Modified: 2017-12-20 16:15 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 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");