Problem 1009 - uninitialized variable in G4SteppingManager::SetInitialStep(...)
Summary: uninitialized variable in G4SteppingManager::SetInitialStep(...)
Status: RESOLVED FIXED
Alias: None
Product: Geant4
Classification: Unclassified
Component: tracking (show other problems)
Version: 9.1
Hardware: All All
: P5 normal
Assignee: Takashi.Sasaki
URL:
Depends on:
Blocks:
 
Reported: 2008-04-04 18:59 CEST by Tom Roberts
Modified: 2008-05-06 14:58 CEST (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this problem.
Description Tom Roberts 2008-04-04 18:59:34 CEST
This is Geant4.9.1.p01.

In G4SteppingManager::SetInitialStep(...) it is possible to leave fTouchableHandle uninitialized. In virtually all cases the code does not follow this pathway, so it works. But I have problems with it when starting to track a secondary.

In G4SteppingManager.cc, just before line 310, add
    fTouchableHandle = fTrack->GetTouchableHandle();

This is right after the }else{ from an if testing fTrack->GetTouchableHandle().

Note: it is possible that this should use fNavigator->CreateTouchableHistory() instead, I'm not sure. The code in this }else{ looks strange, as it is setting the track touchable handle BEFORE resetting the navigator. Perhaps it should bbe re-visited.
Comment 1 Takashi.Sasaki 2008-04-22 13:18:09 CEST
I am very sorry, but I do not understand what you want to do and what is your problem. Could write more detail about your problem?
Comment 2 Tom Roberts 2008-04-22 18:14:07 CEST
This is purely a C++ issue -- G4SteppingManager::SetInitialStep(...) must initialize fTouchableHandle for the current track, and there is a possible path through the code in which it is not initialized. This has not been noticed before because it is quite rare to follow this path, but I now have code which does so (it crashes because of the uninitialized variable).

In my local copy of the code I fixed it this way (just after line 309):
    fTouchableHandle = fTrack->GetTouchableHandle();
and this solved my problem. But I don't know enough about the behavior of the code, and it's possible that it should be:
    fTouchableHandle = fNavigator->CreateTouchableHistory()
(I base this on the way the surrounding code looks.) In particular, it is possible that my fix uses the wrong touchable handle. In my case, possibly having the wrong touchable handle does not seem to be a problem, but in general that might not be true, so someone who understand the details of this code should look at it. In any case, SOME initialization of fTouchableHandle with a valid touchable handle is needed inside that }else{ at line 309. Note that the code is setting the track touchable handle BEFORE resetting the navigator, which might well be incorrect. It should be looked at in detail by someone who understands what is happening (i.e. how the navigator, track, and touchable handle are inter-related).
Comment 3 Takashi.Sasaki 2008-05-06 14:58:04 CEST
Thank you very much for reporting the problem. I have fixed the code and committed on CVS.