Geant4 Version: 11.2.2
Operating System: macOS 15.1 beta 3
Compiler/Version: gcc 14.1.0
CMake Version: 3.30.2
I made some modifications to the human_phantom example to generate random points to shoot alpha particles in the range of the lung. Here’s a diff patch file(change the extension to .diff. I had to change to .txt because I can’t upload .diff files for some reason):
human_phantom_patch.txt (11.8 KB)
However, double-free error occurs. Here’s the error log:
==24215==ERROR: AddressSanitizer: attempting double-free on 0x60200072ed90 in thread T4:
#0 0x1079a82d4 in _ZdlPv+0x74 (libclang_rt.asan_osx_dynamic.dylib:arm64e+0x642d4)
#1 0x1041cbbe4 in G4SolidStore::DeRegister(G4VSolid*)+0x26c (libG4geometry.dylib:arm64+0x83be4)
#2 0x1041cd50c in G4VSolid::~G4VSolid()+0x24 (libG4geometry.dylib:arm64+0x8550c)
#3 0x10421c67c in G4Box::~G4Box()+0x8 (libG4geometry.dylib:arm64+0xd467c)
#4 0x102f2b800 in std::__1::default_delete<G4Box>::operator()[abi:ne180100](G4Box*) const unique_ptr.h:66
#5 0x102f2b6f0 in std::__1::unique_ptr<G4Box, std::__1::default_delete<G4Box>>::reset[abi:ne180100](G4Box*) unique_ptr.h:266
#6 0x102f2b604 in std::__1::unique_ptr<G4Box, std::__1::default_delete<G4Box>>::~unique_ptr[abi:ne180100]() unique_ptr.h:236
#7 0x102f2a74c in std::__1::unique_ptr<G4Box, std::__1::default_delete<G4Box>>::~unique_ptr[abi:ne180100]() unique_ptr.h:236
#8 0x102f29b60 in G4HumanPhantomPrimaryGeneratorAction::SetRandomPositionInLung() G4HumanPhantomPrimaryGeneratorAction.cc:65
#9 0x102f2a808 in G4HumanPhantomPrimaryGeneratorAction::GeneratePrimaries(G4Event*) G4HumanPhantomPrimaryGeneratorAction.cc:70
#10 0x103b61bf4 in G4WorkerTaskRunManager::GenerateEvent(int)+0x828 (libG4run.dylib:arm64+0x59bf4)
#11 0x103b61284 in G4WorkerTaskRunManager::ProcessOneEvent(int)+0x20 (libG4run.dylib:arm64+0x59284)
#12 0x103b6120c in G4WorkerTaskRunManager::DoEventLoop(int, char const*, int)+0xe4 (libG4run.dylib:arm64+0x5920c)
#13 0x103b62b5c in G4WorkerTaskRunManager::DoWork()+0x1b0 (libG4run.dylib:arm64+0x5ab5c)
#14 0x103b4d370 in std::__1::__packaged_task_func<std::__1::enable_if<std::is_void<void>::value, void>::type PTL::TaskGroup<void, void, 0l>::exec<G4TaskRunManager::AddEventTask(int)::$_0, void>(G4TaskRunManager::AddEventTask(int)::$_0)::'lambda'(), std::__1::allocator<std::__1::enable_if<std::is_void<void>::value, void>::type PTL::TaskGroup<void, void, 0l>::exec<G4TaskRunManager::AddEventTask(int)::$_0, void>(G4TaskRunManager::AddEventTask(int)::$_0)::'lambda'()>, void ()>::operator()()+0x28 (libG4run.dylib:arm64+0x45370)
#15 0x103b4d44c in std::__1::packaged_task<void ()>::operator()()+0x4c (libG4run.dylib:arm64+0x4544c)
#16 0x1036b1a80 in PTL::ThreadPool::execute_thread(PTL::VUserTaskQueue*)+0x3e0 (libG4ptl.2.3.3.dylib:arm64+0x9a80)
#17 0x1036b11b0 in PTL::ThreadPool::start_thread(PTL::ThreadPool*, std::__1::vector<std::__1::shared_ptr<PTL::ThreadData>, std::__1::allocator<std::__1::shared_ptr<PTL::ThreadData>>>*, long)+0x2b8 (libG4ptl.2.3.3.dylib:arm64+0x91b0)
#18 0x1036b7c58 in void* std::__1::__thread_proxy[abi:ne180100]<std::__1::tuple<std::__1::unique_ptr<std::__1::__thread_struct, std::__1::default_delete<std::__1::__thread_struct>>, void (*)(PTL::ThreadPool*, std::__1::vector<std::__1::shared_ptr<PTL::ThreadData>, std::__1::allocator<std::__1::shared_ptr<PTL::ThreadData>>>*, long), PTL::ThreadPool*, std::__1::vector<std::__1::shared_ptr<PTL::ThreadData>, std::__1::allocator<std::__1::shared_ptr<PTL::ThreadData>>>*, unsigned long>>(void*)+0x34 (libG4ptl.2.3.3.dylib:arm64+0xfc58)
#19 0x107995858 in asan_thread_start(void*)+0x40 (libclang_rt.asan_osx_dynamic.dylib:arm64e+0x51858)
#20 0x18d4532e0 in _pthread_start+0x84 (libsystem_pthread.dylib:arm64e+0x72e0)
#21 0x18d44e0f8 in thread_start+0x4 (libsystem_pthread.dylib:arm64e+0x20f8)
0x60200072ed90 is located 0 bytes inside of 8-byte region [0x60200072ed90,0x60200072ed98)
freed by thread T6 here:
#0 0x1079a82d4 in _ZdlPv+0x74 (libclang_rt.asan_osx_dynamic.dylib:arm64e+0x642d4)
#1 0x1041cbbe4 in G4SolidStore::DeRegister(G4VSolid*)+0x26c (libG4geometry.dylib:arm64+0x83be4)
#2 0x1041cd50c in G4VSolid::~G4VSolid()+0x24 (libG4geometry.dylib:arm64+0x8550c)
#3 0x10421c67c in G4Box::~G4Box()+0x8 (libG4geometry.dylib:arm64+0xd467c)
#4 0x102f2b800 in std::__1::default_delete<G4Box>::operator()[abi:ne180100](G4Box*) const unique_ptr.h:66
#5 0x102f2b6f0 in std::__1::unique_ptr<G4Box, std::__1::default_delete<G4Box>>::reset[abi:ne180100](G4Box*) unique_ptr.h:266
#6 0x102f2b604 in std::__1::unique_ptr<G4Box, std::__1::default_delete<G4Box>>::~unique_ptr[abi:ne180100]() unique_ptr.h:236
#7 0x102f2a74c in std::__1::unique_ptr<G4Box, std::__1::default_delete<G4Box>>::~unique_ptr[abi:ne180100]() unique_ptr.h:236
#8 0x102f29b60 in G4HumanPhantomPrimaryGeneratorAction::SetRandomPositionInLung() G4HumanPhantomPrimaryGeneratorAction.cc:65
#9 0x102f2a808 in G4HumanPhantomPrimaryGeneratorAction::GeneratePrimaries(G4Event*) G4HumanPhantomPrimaryGeneratorAction.cc:70
#10 0x103b61bf4 in G4WorkerTaskRunManager::GenerateEvent(int)+0x828 (libG4run.dylib:arm64+0x59bf4)
#11 0x103b61284 in G4WorkerTaskRunManager::ProcessOneEvent(int)+0x20 (libG4run.dylib:arm64+0x59284)
#12 0x103b6120c in G4WorkerTaskRunManager::DoEventLoop(int, char const*, int)+0xe4 (libG4run.dylib:arm64+0x5920c)
#13 0x103b62b5c in G4WorkerTaskRunManager::DoWork()+0x1b0 (libG4run.dylib:arm64+0x5ab5c)
#14 0x103b4d370 in std::__1::__packaged_task_func<std::__1::enable_if<std::is_void<void>::value, void>::type PTL::TaskGroup<void, void, 0l>::exec<G4TaskRunManager::AddEventTask(int)::$_0, void>(G4TaskRunManager::AddEventTask(int)::$_0)::'lambda'(), std::__1::allocator<std::__1::enable_if<std::is_void<void>::value, void>::type PTL::TaskGroup<void, void, 0l>::exec<G4TaskRunManager::AddEventTask(int)::$_0, void>(G4TaskRunManager::AddEventTask(int)::$_0)::'lambda'()>, void ()>::operator()()+0x28 (libG4run.dylib:arm64+0x45370)
#15 0x103b4d44c in std::__1::packaged_task<void ()>::operator()()+0x4c (libG4run.dylib:arm64+0x4544c)
#16 0x1036b1a80 in PTL::ThreadPool::execute_thread(PTL::VUserTaskQueue*)+0x3e0 (libG4ptl.2.3.3.dylib:arm64+0x9a80)
#17 0x1036b11b0 in PTL::ThreadPool::start_thread(PTL::ThreadPool*, std::__1::vector<std::__1::shared_ptr<PTL::ThreadData>, std::__1::allocator<std::__1::shared_ptr<PTL::ThreadData>>>*, long)+0x2b8 (libG4ptl.2.3.3.dylib:arm64+0x91b0)
#18 0x1036b7c58 in void* std::__1::__thread_proxy[abi:ne180100]<std::__1::tuple<std::__1::unique_ptr<std::__1::__thread_struct, std::__1::default_delete<std::__1::__thread_struct>>, void (*)(PTL::ThreadPool*, std::__1::vector<std::__1::shared_ptr<PTL::ThreadData>, std::__1::allocator<std::__1::shared_ptr<PTL::ThreadData>>>*, long), PTL::ThreadPool*, std::__1::vector<std::__1::shared_ptr<PTL::ThreadData>, std::__1::allocator<std::__1::shared_ptr<PTL::ThreadData>>>*, unsigned long>>(void*)+0x34 (libG4ptl.2.3.3.dylib:arm64+0xfc58)
#19 0x107995858 in asan_thread_start(void*)+0x40 (libclang_rt.asan_osx_dynamic.dylib:arm64e+0x51858)
#20 0x18d4532e0 in _pthread_start+0x84 (libsystem_pthread.dylib:arm64e+0x72e0)
#21 0x18d44e0f8 in thread_start+0x4 (libsystem_pthread.dylib:arm64e+0x20f8)
previously allocated by thread T4 here:
#0 0x1079a7e94 in _Znwm+0x74 (libclang_rt.asan_osx_dynamic.dylib:arm64e+0x63e94)
#1 0x1041be288 in std::__1::pair<G4String, std::__1::vector<G4VPhysicalVolume*, std::__1::allocator<G4VPhysicalVolume*>>>::pair[abi:ne180100]<G4String const&, std::__1::vector<G4VPhysicalVolume*, std::__1::allocator<G4VPhysicalVolume*>>&, 0>(G4String const&, std::__1::vector<G4VPhysicalVolume*, std::__1::allocator<G4VPhysicalVolume*>>&)+0x8c (libG4geometry.dylib:arm64+0x76288)
#2 0x1041cb718 in G4SolidStore::Register(G4VSolid*)+0x2b4 (libG4geometry.dylib:arm64+0x83718)
#3 0x1041cd3c0 in G4VSolid::G4VSolid(G4String const&)+0x64 (libG4geometry.dylib:arm64+0x853c0)
#4 0x10421dd38 in G4CSGSolid::G4CSGSolid(G4String const&)+0x8 (libG4geometry.dylib:arm64+0xd5d38)
#5 0x10421c2f4 in G4Box::G4Box(G4String const&, double, double, double)+0x34 (libG4geometry.dylib:arm64+0xd42f4)
#6 0x102f2b0b8 in std::__1::__unique_if<G4Box>::__unique_single std::__1::make_unique[abi:ne180100]<G4Box, char const (&) [13], double&, double&, double&>(char const (&) [13], double&, double&, double&) unique_ptr.h:597
#7 0x102f2a2f0 in G4HumanPhantomPrimaryGeneratorAction::right_construct() G4HumanPhantomPrimaryGeneratorAction.cc:98
#8 0x102f298cc in G4HumanPhantomPrimaryGeneratorAction::SetRandomPositionInLung() G4HumanPhantomPrimaryGeneratorAction.cc:55
#9 0x102f2a808 in G4HumanPhantomPrimaryGeneratorAction::GeneratePrimaries(G4Event*) G4HumanPhantomPrimaryGeneratorAction.cc:70
#10 0x103b61bf4 in G4WorkerTaskRunManager::GenerateEvent(int)+0x828 (libG4run.dylib:arm64+0x59bf4)
#11 0x103b61284 in G4WorkerTaskRunManager::ProcessOneEvent(int)+0x20 (libG4run.dylib:arm64+0x59284)
#12 0x103b6120c in G4WorkerTaskRunManager::DoEventLoop(int, char const*, int)+0xe4 (libG4run.dylib:arm64+0x5920c)
#13 0x103b62b5c in G4WorkerTaskRunManager::DoWork()+0x1b0 (libG4run.dylib:arm64+0x5ab5c)
#14 0x103b4d370 in std::__1::__packaged_task_func<std::__1::enable_if<std::is_void<void>::value, void>::type PTL::TaskGroup<void, void, 0l>::exec<G4TaskRunManager::AddEventTask(int)::$_0, void>(G4TaskRunManager::AddEventTask(int)::$_0)::'lambda'(), std::__1::allocator<std::__1::enable_if<std::is_void<void>::value, void>::type PTL::TaskGroup<void, void, 0l>::exec<G4TaskRunManager::AddEventTask(int)::$_0, void>(G4TaskRunManager::AddEventTask(int)::$_0)::'lambda'()>, void ()>::operator()()+0x28 (libG4run.dylib:arm64+0x45370)
#15 0x103b4d44c in std::__1::packaged_task<void ()>::operator()()+0x4c (libG4run.dylib:arm64+0x4544c)
#16 0x1036b1a80 in PTL::ThreadPool::execute_thread(PTL::VUserTaskQueue*)+0x3e0 (libG4ptl.2.3.3.dylib:arm64+0x9a80)
#17 0x1036b11b0 in PTL::ThreadPool::start_thread(PTL::ThreadPool*, std::__1::vector<std::__1::shared_ptr<PTL::ThreadData>, std::__1::allocator<std::__1::shared_ptr<PTL::ThreadData>>>*, long)+0x2b8 (libG4ptl.2.3.3.dylib:arm64+0x91b0)
#18 0x1036b7c58 in void* std::__1::__thread_proxy[abi:ne180100]<std::__1::tuple<std::__1::unique_ptr<std::__1::__thread_struct, std::__1::default_delete<std::__1::__thread_struct>>, void (*)(PTL::ThreadPool*, std::__1::vector<std::__1::shared_ptr<PTL::ThreadData>, std::__1::allocator<std::__1::shared_ptr<PTL::ThreadData>>>*, long), PTL::ThreadPool*, std::__1::vector<std::__1::shared_ptr<PTL::ThreadData>, std::__1::allocator<std::__1::shared_ptr<PTL::ThreadData>>>*, unsigned long>>(void*)+0x34 (libG4ptl.2.3.3.dylib:arm64+0xfc58)
#19 0x107995858 in asan_thread_start(void*)+0x40 (libclang_rt.asan_osx_dynamic.dylib:arm64e+0x51858)
#20 0x18d4532e0 in _pthread_start+0x84 (libsystem_pthread.dylib:arm64e+0x72e0)
#21 0x18d44e0f8 in thread_start+0x4 (libsystem_pthread.dylib:arm64e+0x20f8)
Thread T4 created by T0 here:
#0 0x1079901c8 in pthread_create+0x5c (libclang_rt.asan_osx_dynamic.dylib:arm64e+0x4c1c8)
#1 0x1036b2ea4 in PTL::ThreadPool::initialize_threadpool(unsigned long)+0x134 (libG4ptl.2.3.3.dylib:arm64+0xaea4)
#2 0x1036b2b20 in PTL::ThreadPool::ThreadPool(PTL::ThreadPool::Config const&)+0x36c (libG4ptl.2.3.3.dylib:arm64+0xab20)
#3 0x1036b419c in PTL::ThreadPool::ThreadPool(unsigned long const&, PTL::VUserTaskQueue*, bool, std::__1::function<long (long)>, std::__1::function<void ()>, std::__1::function<void ()>)+0x190 (libG4ptl.2.3.3.dylib:arm64+0xc19c)
#4 0x1036ad0c4 in PTL::TaskRunManager::Initialize(unsigned long long)+0x2e8 (libG4ptl.2.3.3.dylib:arm64+0x50c4)
#5 0x103b473d8 in G4TaskRunManager::InitializeThreadPool()+0x78 (libG4run.dylib:arm64+0x3f3d8)
#6 0x103b47330 in G4TaskRunManager::Initialize()+0x4c (libG4run.dylib:arm64+0x3f330)
#7 0x103cff3fc in G4UIcommand::DoIt(G4String)+0x8cc (libG4intercoms.dylib:arm64+0x133fc)
#8 0x103d17cd8 in G4UImanager::ApplyCommand(char const*)+0xeac (libG4intercoms.dylib:arm64+0x2bcd8)
#9 0x103cfa3e4 in G4UIbatch::ExecCommand(G4String const&)+0x20 (libG4intercoms.dylib:arm64+0xe3e4)
#10 0x103cfa764 in G4UIbatch::SessionStart()+0x13c (libG4intercoms.dylib:arm64+0xe764)
#11 0x103d143b8 in G4UImanager::ExecuteMacroFile(char const*)+0x44 (libG4intercoms.dylib:arm64+0x283b8)
#12 0x103d0fce8 in G4UIcontrolMessenger::SetNewValue(G4UIcommand*, G4String)+0xc4 (libG4intercoms.dylib:arm64+0x23ce8)
#13 0x103cff3fc in G4UIcommand::DoIt(G4String)+0x8cc (libG4intercoms.dylib:arm64+0x133fc)
#14 0x103d17cd8 in G4UImanager::ApplyCommand(char const*)+0xeac (libG4intercoms.dylib:arm64+0x2bcd8)
#15 0x103cfa3e4 in G4UIbatch::ExecCommand(G4String const&)+0x20 (libG4intercoms.dylib:arm64+0xe3e4)
#16 0x103cfa764 in G4UIbatch::SessionStart()+0x13c (libG4intercoms.dylib:arm64+0xe764)
#17 0x103d143b8 in G4UImanager::ExecuteMacroFile(char const*)+0x44 (libG4intercoms.dylib:arm64+0x283b8)
#18 0x103d0fce8 in G4UIcontrolMessenger::SetNewValue(G4UIcommand*, G4String)+0xc4 (libG4intercoms.dylib:arm64+0x23ce8)
#19 0x103cff3fc in G4UIcommand::DoIt(G4String)+0x8cc (libG4intercoms.dylib:arm64+0x133fc)
#20 0x103d17cd8 in G4UImanager::ApplyCommand(char const*)+0xeac (libG4intercoms.dylib:arm64+0x2bcd8)
#21 0x102eeeab0 in main phantom.cc:67
#22 0x18d0d0270 (<unknown module>)
Thread T6 created by T0 here:
#0 0x1079901c8 in pthread_create+0x5c (libclang_rt.asan_osx_dynamic.dylib:arm64e+0x4c1c8)
#1 0x1036b2ea4 in PTL::ThreadPool::initialize_threadpool(unsigned long)+0x134 (libG4ptl.2.3.3.dylib:arm64+0xaea4)
#2 0x1036b2b20 in PTL::ThreadPool::ThreadPool(PTL::ThreadPool::Config const&)+0x36c (libG4ptl.2.3.3.dylib:arm64+0xab20)
#3 0x1036b419c in PTL::ThreadPool::ThreadPool(unsigned long const&, PTL::VUserTaskQueue*, bool, std::__1::function<long (long)>, std::__1::function<void ()>, std::__1::function<void ()>)+0x190 (libG4ptl.2.3.3.dylib:arm64+0xc19c)
#4 0x1036ad0c4 in PTL::TaskRunManager::Initialize(unsigned long long)+0x2e8 (libG4ptl.2.3.3.dylib:arm64+0x50c4)
#5 0x103b473d8 in G4TaskRunManager::InitializeThreadPool()+0x78 (libG4run.dylib:arm64+0x3f3d8)
#6 0x103b47330 in G4TaskRunManager::Initialize()+0x4c (libG4run.dylib:arm64+0x3f330)
#7 0x103cff3fc in G4UIcommand::DoIt(G4String)+0x8cc (libG4intercoms.dylib:arm64+0x133fc)
#8 0x103d17cd8 in G4UImanager::ApplyCommand(char const*)+0xeac (libG4intercoms.dylib:arm64+0x2bcd8)
#9 0x103cfa3e4 in G4UIbatch::ExecCommand(G4String const&)+0x20 (libG4intercoms.dylib:arm64+0xe3e4)
#10 0x103cfa764 in G4UIbatch::SessionStart()+0x13c (libG4intercoms.dylib:arm64+0xe764)
#11 0x103d143b8 in G4UImanager::ExecuteMacroFile(char const*)+0x44 (libG4intercoms.dylib:arm64+0x283b8)
#12 0x103d0fce8 in G4UIcontrolMessenger::SetNewValue(G4UIcommand*, G4String)+0xc4 (libG4intercoms.dylib:arm64+0x23ce8)
#13 0x103cff3fc in G4UIcommand::DoIt(G4String)+0x8cc (libG4intercoms.dylib:arm64+0x133fc)
#14 0x103d17cd8 in G4UImanager::ApplyCommand(char const*)+0xeac (libG4intercoms.dylib:arm64+0x2bcd8)
#15 0x103cfa3e4 in G4UIbatch::ExecCommand(G4String const&)+0x20 (libG4intercoms.dylib:arm64+0xe3e4)
#16 0x103cfa764 in G4UIbatch::SessionStart()+0x13c (libG4intercoms.dylib:arm64+0xe764)
#17 0x103d143b8 in G4UImanager::ExecuteMacroFile(char const*)+0x44 (libG4intercoms.dylib:arm64+0x283b8)
#18 0x103d0fce8 in G4UIcontrolMessenger::SetNewValue(G4UIcommand*, G4String)+0xc4 (libG4intercoms.dylib:arm64+0x23ce8)
#19 0x103cff3fc in G4UIcommand::DoIt(G4String)+0x8cc (libG4intercoms.dylib:arm64+0x133fc)
#20 0x103d17cd8 in G4UImanager::ApplyCommand(char const*)+0xeac (libG4intercoms.dylib:arm64+0x2bcd8)
#21 0x102eeeab0 in main phantom.cc:67
#22 0x18d0d0270 (<unknown module>)
SUMMARY: AddressSanitizer: double-free (libclang_rt.asan_osx_dynamic.dylib:arm64e+0x642d4) in _ZdlPv+0x74
==24215==ABORTING
[1] 24215 abort ./phantom
How can I fix this? I’m quite certain that my solution to doing this is wrong. I’m also open for better approaches.