Problem 1171 - Segmentation fault from GetCreatorProcess()
Summary: Segmentation fault from GetCreatorProcess()
Status: RESOLVED INVALID
Alias: None
Product: Geant4
Classification: Unclassified
Component: event (show other problems)
Version: 9.4
Hardware: PC Linux
: P5 trivial
Assignee: asai
URL:
Depends on:
Blocks:
 
Reported: 2011-02-09 04:40 CET by Neoh Yuen Sim
Modified: 2011-02-10 00:42 CET (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this problem.
Description Neoh Yuen Sim 2011-02-09 04:40:32 CET
I got a segmentation fault when trying to output the creator process of some particles. It turns out the particles are in fact generated by general particle source. Some of them reach directly onto my detector without interaction. It would be nice if g4 can safeguard the output of GetCreatorProcess(),in particular when the particles detected are from particle gun itself.
Comment 1 Michael Kelsey 2011-02-09 22:19:46 CET
(In reply to comment #0)
> I got a segmentation fault when trying to output the creator process of some
> particles. It turns out the particles are in fact generated by general particle
> source. Some of them reach directly onto my detector without interaction. It
> would be nice if g4 can safeguard the output of GetCreatorProcess(),in
> particular when the particles detected are from particle gun itself.

If the particle is not a secondary, then GetCreatorProcess() correctly returns a null pointer.  The client code (i.e., your user action) is responsible for testing returned pointers for null before dereferencing them.  See, for example, examples/advanced/composite_calorimeter/src/CCaloSD.cc.

Note that, despite this injunction, several of the examples do not properly test the pointer before derefencing to get the process name.
Comment 2 asai 2011-02-10 00:42:16 CET
As Mike wrote, this is the way how this method behaves, and null-pointer protection is suggested in the user's code. See for example this HyperNews posting.
http://hypernews.slac.stanford.edu/HyperNews/geant4/get/eventtrackmanage/919/1.html