fixed errors
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -17,6 +17,14 @@ DetectorActionInitialization::DetectorActionInitialization(EmitterPrimary *emitt
|
||||
{}
|
||||
|
||||
DetectorActionInitialization::~DetectorActionInitialization() {}
|
||||
|
||||
class DetectorSteppingActionWrapper : public G4UserSteppingAction {
|
||||
public:
|
||||
DetectorSteppingActionWrapper(DetectorSteppingAction *real) : m_Real(real) {}
|
||||
virtual void UserSteppingAction(const G4Step* step) override { m_Real->UserSteppingAction(step); }
|
||||
private:
|
||||
DetectorSteppingAction *m_Real;
|
||||
};
|
||||
|
||||
void DetectorActionInitialization::BuildForMaster() const {}
|
||||
|
||||
@@ -34,8 +42,10 @@ void DetectorActionInitialization::Build() const {
|
||||
if (m_Output) {
|
||||
DetectorSteppingAction *sa = new DetectorSteppingAction(m_Output, m_Planes);
|
||||
sa->SetVerbosity(m_Verbosity);
|
||||
SetUserAction(static_cast<G4UserSteppingAction*>(sa));
|
||||
// EventManager will delete sa via the Event slot
|
||||
SetUserAction(static_cast<G4UserEventAction*>(sa));
|
||||
// EventManager will delete the wrapper, leaving sa alive for the other deletion.
|
||||
SetUserAction(new DetectorSteppingActionWrapper(sa));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ static void CheckGeant4Environment() {
|
||||
|
||||
class SceneImpl {
|
||||
public:
|
||||
SceneImpl() : m_RunManager(G4RunManagerFactory::CreateRunManager(G4RunManagerType::Default)),
|
||||
SceneImpl() : m_RunManager(G4RunManagerFactory::CreateRunManager(G4RunManagerType::Serial)),
|
||||
m_Emitter(nullptr),
|
||||
m_InitCalled(false) {
|
||||
m_RunManager->SetUserInitialization(new PhysicsList);
|
||||
|
||||
Reference in New Issue
Block a user