Segment Fault when Creating a new Material

_Geant4 Version:_11.3.0
_Operating System:_Windows 10
Compiler/Version:
_CMake Version:_3.31.4

Whenever I created the material I have named Mold my simulation outputs a segment fault. I am confused as to why this is happening and any help is appreciated.

    G4Material *Mold = new G4Material("Mold", 1.82*g/cm3, 5);
    Mold -> AddMaterial(SiO2, 89.2*perCent);
	Mold -> AddMaterial(Phenol_Resin, 4*perCent);
	Mold -> AddMaterial(Epoxy_Resin1, 3*perCent);
    Mold -> AddMaterial(Epoxy_Resin2, 3.5*perCent);
	Mold -> AddElement(C, 0.3*perCent);

Not enough information in that code snippet. Which line has the segfault?
Have you checked that all five of the materials you make use of were defined before this point in your code?

I am unsure of which line has the segment fault, whenever I run the code the output is “C:\dev\Geant4\geant4-v11.3.0-install\share\Geant4\geant4make\shielding\build\Release\shielding.exe (process 6400) exited with code -1073741819 (0xc0000005).” I am running the code through visual studio 2022.

I have attached my definition of the materials here:

G4Material  *SiO2 = new G4Material("SiO2", 2.201*g/cm3, 3);
SiO2 -> AddElement(nist -> FindOrBuildElement("Si"), 1);
SiO2 -> AddElement(nist -> FindOrBuildElement("O"), 2);

//Phenol Resin (Phenolic novolak)
G4Material *Phenol_Resin = new G4Material("Phenol_Resin", 1.82*g/cm3, 17);
Phenol_Resin -> AddElement(nist -> FindOrBuildElement("H"), 9);
Phenol_Resin -> AddElement(nist -> FindOrBuildElement("O"), 1);
Phenol_Resin -> AddElement(nist -> FindOrBuildElement("C"), 7);

//Epoxy Resin1 (Epoxy cresol novolak)
G4Material *Epoxy_Resin1 = new G4Material("Epoxy_Resin1", 1.256*g/cm3, 29);
Epoxy_Resin1 -> AddElement(nist -> FindOrBuildElement("H"), 16);
Epoxy_Resin1 -> AddElement(nist -> FindOrBuildElement("O"), 2);
Epoxy_Resin1 -> AddElement(nist -> FindOrBuildElement("C"), 11);

//Epoxy Resin2 (Polymide Resin)
G4Material *Epoxy_Resin2 = new G4Material("Epoxy_Resin2", 1.256*g/cm3, 51);
Epoxy_Resin2 -> AddElement(nist -> FindOrBuildElement("H"), 22);
Epoxy_Resin2 -> AddElement(nist -> FindOrBuildElement("O"), 5);
Epoxy_Resin2 -> AddElement(nist -> FindOrBuildElement("C"), 22);
Epoxy_Resin2 -> AddElement(nist -> FindOrBuildElement("N"), 2);

//Carbon Black
G4Element *C = nist -> FindOrBuildElement("C");

I solved the problem by converting all of my arguments in the second position of the FindOrBuildElement function to percentages. This made my program run without a 0xC0000005 error, the only question left on this thread is why did I need to make a conversion from a number argument to a percentage argument.
A quick example of what I mean:

SiO2 -> AddElement(nist -> FindOrBuildElement("C"), 1); 
//convert to this form:
SiO2 -> AddElement(nist -> FindOrBuildElement("C"), 33.33*perCent);

SiO2 has 2 components, not 3
Phenol has 3 components, resin1: 3, and resin2: 4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.