fixed errors

This commit is contained in:
AndreaRigoni
2026-03-25 20:30:46 +00:00
parent 6a65fe94c8
commit e4a8499104
17 changed files with 344 additions and 269 deletions

View File

@@ -12,6 +12,15 @@ ActionInitialization::ActionInitialization(EmitterPrimary *emitter, SimulationCo
{}
ActionInitialization::~ActionInitialization() {}
// Lightweight wrapper to avoid double-free in Geant4 EventManager
class SteppingActionWrapper : public G4UserSteppingAction {
public:
SteppingActionWrapper(SteppingAction *real) : m_Real(real) {}
virtual void UserSteppingAction(const G4Step* step) override { m_Real->UserSteppingAction(step); }
private:
SteppingAction *m_Real;
};
void ActionInitialization::BuildForMaster() const {}
@@ -21,10 +30,12 @@ void ActionInitialization::Build() const {
} else {
SetUserAction(new EmitterPrimary());
}
SteppingAction *sa = new SteppingAction(m_Context);
SetUserAction(static_cast<G4UserSteppingAction*>(sa));
// EventManager will delete sa via this slot
SetUserAction(static_cast<G4UserEventAction*>(sa));
// EventManager will delete the wrapper, leaving sa alive to be deleted once.
SetUserAction(new SteppingActionWrapper(sa));
}
} // namespace Geant