Skip to content

Commit ca9c451

Browse files
authored
Merge pull request #165 from zhaozhiwen/fix/113-touchable-state-leak
Clone the registry GTouchable per step to stop cross-event state leak
2 parents 422513a + 0f2922a commit ca9c451

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

gemc/gsd/gsd.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,9 @@ class GSensitiveDetector : public GBase<GSensitiveDetector>, public G4VSensitive
195195
std::string vname = thisStep->GetPreStepPoint()->GetTouchable()->GetVolume()->GetName();
196196

197197
auto it = gTouchableMap.find(vname);
198-
if (it != gTouchableMap.end()) { return it->second; }
198+
// Return a per-step copy: ProcessHits and processTouchable mutate trackId, pid and the
199+
// time-cell index, so the registry entry must stay pristine across steps and events.
200+
if (it != gTouchableMap.end()) { return std::make_shared<GTouchable>(*it->second); }
199201
// If not found, log an error. The calling code assumes a valid pointer.
200202
log->error(ERR_DYNAMICPLUGINNOTFOUND, "GTouchable for volume " + vname + " not found in gTouchableMap");
201203
}

0 commit comments

Comments
 (0)