Break Segmentation violation while setting a region and adding root logical volumes

Hello everyone!
I am trying to impose step limits and cuts on a specific region and I get a Break segmentation violation problem. I must say that imposing limits and cuts directly on a logical volume does not cause any troubles in my code.

So, in my file, I do the following:

void PhysicsList::SetDosimetryCuts()
  //Forcing low-energy limit for production
  G4ProductionCutsTable::GetProductionCutsTable() ->SetEnergyRange(100*eV, 100.*GeV);

  G4String regionName = "stepLimitRegion2";
  G4Region* Detregion = G4RegionStore::GetInstance()->GetRegion(regionName);

  G4ProductionCuts* cuts = new G4ProductionCuts();
  cuts -> SetProductionCut(0.001*mm,"gamma");
  cuts -> SetProductionCut(0.001*mm,"e-");
  cuts -> SetProductionCut(0.001*mm,"e+");

  G4double stepMax = 1*um;
  G4double trackMax = 1*um;
  G4UserLimits* limits = new G4UserLimits();
  limits -> SetMaxAllowedStep(stepMax);
  limits -> SetUserMaxTrackLength(trackMax);

    Detregion -> SetProductionCuts(cuts);
    Detregion -> SetUserLimits(limits);
         G4cout << "### stepLimitRegion2 gamma production cut = " << G4BestUnit(Detregion->GetProductionCuts()->GetProductionCut("gamma"), "Length") << G4endl;
    G4cout << "### G4Region with name " << regionName << " not found" << G4endl;

While in my file I have the following code (where I create a region with two logical volumes):

  stepLimitRegion2 = new G4Region("stepLimitRegion2");

The Break Segmentation violation occurs when I add the AddRootLogicalVolume lines:


When I remove them, the code runs but step limits/cuts are not assigned. I guess I may be using the Region designation in the in a wrong way…

Any ideas? Thanks!


Dear @asaim,
I have seen you replying to a similar question before. Do you happen to have any idea on why the segmentation fault occurs in my simulations?

Thanks a lot in advance!