This is a part of my code in SteppingAction.I run it,but the system warn me that “Segmentation fault (core dumped)”.I don’t know why?
Primarily,I want to set the processname as a kind of arguments.And transmit it to eventaction.
You create a pointer to a G4VProcess named process. When you call:
You are creating a pointer, but that pointer doesn’t point to anything because it is never assigned an address to point to. What you would like to do, is take either your pre or post step points and print the process name. You can do so like this:
G4cout << "ProcName: " << step->GetPreStepPoint()->GetProcessDefinedStep()->GetProcessName() << G4endl;
If you want to store your process name and pass it to event action like you mentioned you can store it with:
const G4String& procName = step->GetPreStepPoint()->GetProcessDefinedStep()->GetProcessName();
I hope this is helpful,
Okay, I try it.But, it still show me “Segmentation fault (core dumped)” in terminal.
try protecting with
Great!! Question has been solved! Thanks.
Thanks for your help.
This kind of error always occur recently.
Good coding practice is that you should never dereference a pointer without checking that it is valid (non-null) first. It’s true that in user functions called in Geant4, you can “assume” that a lot of the pointers “can’t be” null, but that merely encourages bad practices. Check your pointers before using them.