Generating events in simulation never complete

Hi guys, I want to run my simulation to generate events and create root file, I’m using macOS:15.5,
ROOT: 6.36.0,
Geant4: 11.2.0.
I have Xcode installed, and I’m running it from Terminal
Every time I try to run the simulation, it always gives me different errors such as:
1.

sim(82838,0x16db1b000) malloc: Heap corruption detected, free list is damaged at 0x6000015f5780
*** Incorrect guard value: 4550659104
sim(82838,0x16db1b000) malloc: *** set a breakpoint in malloc_error_break to debug
sim(82838,0x16dba7000) malloc: Heap corruption detected, free list is damaged at 0x60000161c780
*** Incorrect guard value: 0
sim(82838,0x16dba7000) malloc: *** set a breakpoint in malloc_error_break to debug
sim(82838,0x16d7d3000) malloc: Heap corruption detected, free list is damaged at 0x6000015f3f80
*** Incorrect guard value: 0
sim(82838,0x16d7d3000) malloc: *** set a breakpoint in malloc_error_break to debug
[/opt/homebrew/Cellar/root/6.36.00/lib/root/libCling.so] (anonymous namespace)::EmptySubobjectMap::EmptySubobjectMap(clang::ASTContext const&, clang::CXXRecordDecl const*) (no debug info)
[/opt/homebrew/Cellar/root/6.36.00/lib/root/libCling.so] clang::ASTContext::getASTRecordLayout(clang::RecordDecl const*) const (no debug info)
[/opt/homebrew/Cellar/root/6.36.00/lib/root/libCling.so] (anonymous namespace)::EmptySubobjectMap::EmptySubobjectMap(clang::ASTContext const&, clang::CXXRecordDecl const*) (no debug info)
[/opt/homebrew/Cellar/root/6.36.00/lib/root/libCling.so] clang::ASTContext::getASTRecordLayout(clang::RecordDecl const*) const (no debug info)
 (no debug info)
[/opt/homebrew/Cellar/root/6.36.00/lib/root/libRIO.so] TBufferFile::WriteClassBuffer(TClass const*, void*) (no debug info)
[/opt/homebrew/Cellar/root/6.36.00/lib/root/libRIO.so] TKey::TKey(TObject const*, char const*, int, TDirectory*) (no debug info)
[/opt/homebrew/Cellar/root/6.36.00/lib/root/libRIO.so] TFile::CreateKey(TDirectory*, TObject const*, char const*, int) (no debug info)
[/opt/homebrew/Cellar/root/6.36.00/lib/root/libRIO.so] TDirectoryFile::WriteTObject(TObject const*, char const*, char const*, int) (no debug info)
[/opt/homebrew/Cellar/root/6.36.00/lib/root/libCore.so] TObject::Write(char const*, int, int) const (no debug info)
[/opt/homebrew/Cellar/root/6.36.00/lib/root/libRIO.so] TDirectoryFile::Write(char const*, int, int) (no debug info)
[/opt/homebrew/Cellar/root/6.36.00/lib/root/libRIO.so] TFile::Write(char const*, int, int) (no debug info)
[/Users/brianhuang/Simulation/build/sim] Recorder::EndOfRecordingRun(G4Run const*) (no debug info)
[/Users/brianhuang/Simulation/build/sim] RunAction::EndOfRunAction(G4Run const*) (no debug info)
[/opt/GEANT4-v11.2.0/GEANT4-BUILD/BuildProducts/lib/libG4run.dylib] G4RunManager::RunTermination() (no debug info)
[/opt/GEANT4-v11.2.0/GEANT4-BUILD/BuildProducts/lib/libG4run.dylib] G4WorkerRunManager::RunTermination() (no debug info)
[/opt/GEANT4-v11.2.0/GEANT4-BUILD/BuildProducts/lib/libG4run.dylib] G4RunManager::BeamOn(int, char const*, int) (no debug info)
[/opt/GEANT4-v11.2.0/GEANT4-BUILD/BuildProducts/lib/libG4run.dylib] G4WorkerRunManager::DoWork() (no debug info)
[/opt/GEANT4-v11.2.0/GEANT4-BUILD/BuildProducts/lib/libG4run.dylib] G4MTRunManagerKernel::StartThread(G4WorkerThread*) (no debug info)
[/opt/GEANT4-v11.2.0/GEANT4-BUILD/BuildProducts/lib/libG4run.dylib] void* std::__1::__thread_proxy[abi:ne190102]<std::__1::tuple<std::__1::unique_ptr<std::__1::__thread_struct, std::__1::default_delete<std::__1::__thread_struct>>, void (*)(G4WorkerThread*), G4WorkerThread*>>(void*) (no debug info)
[/usr/lib/system/libsystem_pthread.dylib] _pthread_start (no debug info)
[/usr/lib/system/libsystem_pthread.dylib] thread_start (no debug info)
[/opt/homebrew/Cellar/root/6.36.00/lib/root/libCling.so] TClingBaseClassInfo::Offset(void*, bool) const (no debug info)
[/opt/homebrew/Cellar/root/6.36.00/lib/root/libCling.so] TClingClassInfo::GetBaseOffset(TClingClassInfo*, void*, bool) (no debug info)
[/opt/homebrew/Cellar/root/6.36.00/lib/root/libCore.so] TClass::GetBaseClassOffset(TClass const*, void*, bool) (no debug info)
[/opt/homebrew/Cellar/root/6.36.00/lib/root/libRIO.so] TBufferIO::WriteObjectAny(void const*, TClass const*, bool) (no debug info)
[/opt/homebrew/Cellar/root/6.36.00/lib/root/libCore.so] TList::Streamer(TBuffer&) (no debug info)
[/opt/homebrew/Cellar/root/6.36.00/lib/root/libRIO.so] TKey::TKey(TObject const*, char const*, int, TDirectory*) (no debug info)
[/opt/homebrew/Cellar/root/6.36.00/lib/root/libRIO.so] TFile::WriteStreamerInfo() (no debug info)
[/opt/homebrew/Cellar/root/6.36.00/lib/root/libRIO.so] TFile::Write(char const*, int, int) (no debug info)
[/Users/brianhuang/Simulation/build/sim] Recorder::EndOfRecordingRun(G4Run const*) (no debug info)
[/Users/brianhuang/Simulation/build/sim] RunAction::EndOfRunAction(G4Run const*) (no debug info)
[/opt/GEANT4-v11.2.0/GEANT4-BUILD/BuildProducts/lib/libG4run.dylib] G4RunManager::RunTermination() (no debug info)
[/opt/GEANT4-v11.2.0/GEANT4-BUILD/BuildProducts/lib/libG4run.dylib] G4WorkerRunManager::RunTermination() (no debug info)
[/opt/GEANT4-v11.2.0/GEANT4-BUILD/BuildProducts/lib/libG4run.dylib] G4RunManager::BeamOn(int, char const*, int) (no debug info)
[/opt/GEANT4-v11.2.0/GEANT4-BUILD/BuildProducts/lib/libG4run.dylib] G4WorkerRunManager::DoWork() (no debug info)
[/opt/GEANT4-v11.2.0/GEANT4-BUILD/BuildProducts/lib/libG4run.dylib] G4MTRunManagerKernel::StartThread(G4WorkerThread*) (no debug info)
[/opt/GEANT4-v11.2.0/GEANT4-BUILD/BuildProducts/lib/libG4run.dylib] void* std::__1::__thread_proxy[abi:ne190102]<std::__1::tuple<std::__1::unique_ptr<std::__1::__thread_struct, std::__1::default_delete<std::__1::__thread_struct>>, void (*)(G4WorkerThread*), G4WorkerThread*>>(void*) (no debug info)
[/usr/lib/system/libsystem_pthread.dylib] _pthread_start (no debug info)
[/usr/lib/system/libsystem_pthread.dylib] thread_start (no debug info)
G4WT0 > Non-critical error: mutex lock failure in ~G4Cache<P15G4HadFinalState>. 
G4WT0 > If the RunManagerKernel has been deleted, it failed to delete an allocated resource
G4WT0 > and this destructor is being called after the statics were destroyed.
G4WT0 > Exception: [code: system:22] caught: mutex lock failed: Invalid argument

and sometimes it shows the error about segmentation violation and related to lib.Cling, Core, RIO… etc.

this problem has been bothering me for a while, anyone has an idea how to solve it? any tips or comments will be much appreciated, thanks!

To investigate further, I recommend you run you failing example with valgrind

valgrind --log-file=val.01.log --num-callers=50 --suppressions=$ROOTSYS/etc/valgrind-root.supp myexecutable myargs

thanks for this suggestion, but I don’t think valgrind is compatible with macOS system :(( is there any recommendation I could follow?

Sure it is, check out e.g. How to Install Valgrind on Mac OS X

Hiii, I followed the instruction on the site you shared, and it gave me this message,

valgrind: Linux is required for this software.
Error: valgrind: An unsatisfied requirement failed this build.

It will take too long to start everything all over again with linux system… :cry:
Is there any way to diagnose the issue?