Segmentation violation G4TFileManager

Hello,
I am running a simulation based on example B3a in which at the EndOfRunAction I am copying the output ROOT file and the input file in a folder which gets an automatic name with the current date and time, in the master thread. The ROOT file is scored using G4TScoreNtupleWriter, but I added two histograms separately, The simulations worked until I wanted to use another ROOT function to generate random emission for GeneratePrimaries, and then the code crashed. But even after I removed that piece of code, I still get this segmentation violation, although the output files are still created at the end of simulation.

-------- WWWW ------- G4Exception-START -------- WWWW -------
*** G4Exception : Analysis_W001
      issued by : G4TFileManager<FT>::GetTFile
Failed to get file scoring.root
*** This is just a warning message. ***
-------- WWWW -------- G4Exception-END --------- WWWW -------


 *** Break *** segmentation violation
===========================================================
There was a crash.
This is the entire stack trace of all threads:
===========================================================

I will paste here only a snippet of the error message, but at the very end it is also written:

WARNING - Attempt to delete the physical volume store while geometry closed !
WARNING - Attempt to delete the logical volume store while geometry closed !
WARNING - Attempt to delete the solid store while geometry closed !
WARNING - Attempt to delete the region store while geometry closed !

I would appreciate your help or advice. I tried everything I could!

Best regards,
Raluca

Geant4 Version: v11.2.2
Operating System: ubuntu 24
_CMake Version: 3.16.3