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 PhysicsList.cc 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);

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

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

  stepLimitRegion2 = new G4Region("stepLimitRegion2");
 
  Active_logic->SetRegion(stepLimitRegion2);
  stepLimitRegion2->AddRootLogicalVolume(Active_logic);
  sensitive_logic->SetRegion(stepLimitRegion2);
  stepLimitRegion2->AddRootLogicalVolume(sensitive_logic);

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

  ...
  stepLimitRegion2->AddRootLogicalVolume(Active_logic);
  ...
  stepLimitRegion2->AddRootLogicalVolume(sensitive_logic);

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 DetectorConstruction.cc in a wrong way…

Any ideas? Thanks!

Vasily

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!
Regards,
Vasily