Error when changing GDML geometry to use a different material

Would anyone please enlighten me as to the source of the below error?
I load a GDML geometry from GDMLParser, modify materials and add material properties, and then calculate cross-sections for the materials. (This has been tested and is known to work).

Then I redefine the material with the generated cross-sections (read in from a text file “lambdas5.txt”) and use the following to reload my geometry.

G4RunManager* runManager = G4RunManager::GetRunManager();
G4GeometryManager* geo = G4GeometryManager::GetInstance();
geo->OpenGeometry(World);
WorldBuild((Parser), World);
geo->CloseGeometry(World);
G4VVisManager
visManager = G4VVisManager::GetConcreteInstance();
visManager->GeometryHasChanged();
//runManager->PhysicsHasBeenModified(); // do I need this - only the materials have changed?
runManager->GeometryHasBeenModified();
runManager->ReinitializeGeometry(true);

WorldBuild() basically redefines all the materials with the new cross-sections, and then inside WorldBuild I call WorldMod (below), which sets the volumes to the modified materials. (Here I am setting it to Air instead as a test).

int i = 0;
G4NistManager* man = G4NistManager::Instance();
while(true)
{
G4VPhysicalVolume* V = World->GetLogicalVolume()->GetDaughter(i);
if(V!=NULL)
{
string name = V->GetName();
if(name.find(“EJ208”) != std::string::npos)
{
V->GetLogicalVolume()->SetMaterial(man->FindMaterial(“G4_AIR”));
}
}
else
{
break;
}
i+=1;
}
World->GetLogicalVolume()->GetDaughter(0)->GetLogicalVolume()->GetMaterial()->GetMaterialPropertiesTable()->DumpTable();
}

My console output follows (up until the segfault):


>  > ### Run 0 starts.
> > ### CROSS SECTIONS CREATED 
> > ### UPDATING MPT ...
> > --//-------------------------------------------WORLDBUILDING-------------------------------------------//--
> > G4Material WARNING: duplicate name of material CarbonM
> > G4Material WARNING: duplicate name of material LeadM
> > G4Material WARNING: duplicate name of material Vikuiti
> > G4Material WARNING: duplicate name of material PVT
> > G4Material WARNING: duplicate name of material EJ208
> > OPENING PVT FILE -----------
> > opened file
> > --//-------------------------------------------WORLDMODDING-------------------------------------------//--
> > 0: RINDEX
> > 2.388e-06   1.00029
> > 2.5875e-06   1.00029
> > 2.7e-06   1.00029
> > 2.855e-06   1.00029
> > 2.95714e-06   1.00029
> > 3.105e-06   1.00029
> > 9: GROUPVEL
> > 2.388e-06   299.706
> > 2.48775e-06   299.706
> > 2.64375e-06   299.706
> > 2.7775e-06   299.706
> > 2.90607e-06   299.706
> > 3.105e-06   299.706
> > /vis/scene/notifyHandlers scene-0
> > /run/geometryModified
> > #### Assemblies, Volumes and Solids Stores are wiped out.
> > #### Region <DefaultRegionForParallelWorld> is cleared.
> > /run/reinitializeGeometry
> > ### MPT UPDATED
> > ### Run 0 start.

So clearly everything is updated - I can see the right material properties for G4_AIR, but why do I see a segfault?

GDB where:
#0 0x0000000000000000 in ?? () #1 0x00007fffef5f134b in G4Navigator::LocateGlobalPointAndSetup(CLHEP::Hep3Vector const&, CLHEP::Hep3Vector const*, bool, bool) () from /home/mitt-unix/Bureau/Desktop/Geant4/G4-install/lib/libG4geometry.so #2 0x00007ffff54766f0 in G4EventManager::DoProcessing(G4Event*) () from /home/mitt-unix/Bureau/Desktop/Geant4/G4-install/lib/libG4event.so #3 0x00007ffff5716595 in G4RunManager::ProcessOneEvent(int) () from /home/mitt-unix/Bureau/Desktop/Geant4/G4-install/lib/libG4run.so #4 0x00007ffff571468b in G4RunManager::BeamOn(int, char const*, int) () from /home/mitt-unix/Bureau/Desktop/Geant4/G4-install/lib/libG4run.so #5 0x00007ffff57336e3 in G4RunMessenger::SetNewValue(G4UIcommand*, G4String) () from /home/mitt-unix/Bureau/Desktop/Geant4/G4-install/lib/libG4run.so #6 0x00007fffeed433bc in G4UIcommand::DoIt(G4String) () from /home/mitt-unix/Bureau/Desktop/Geant4/G4-install/lib/libG4intercoms.so #7 0x00007fffeed64c4c in G4UImanager::ApplyCommand(char const*) () from /home/mitt-unix/Bureau/Desktop/Geant4/G4-install/lib/libG4intercoms.so #8 0x00007ffff6e3f132 in G4UIterminal::ExecuteCommand(G4String const&) () from /home/mitt-unix/Bureau/Desktop/Geant4/G4-install/lib/libG4interfaces.so #9 0x00007ffff6e40a0a in G4UIterminal::SessionStart() () from /home/mitt-unix/Bureau/Desktop/Geant4/G4-install/lib/libG4interfaces.so #10 0x00005555555648c2 in main (argc=<optimized out>, argv=0x7fffffffd878) at /home/mitt-unix/Bureau/Desktop/Geant4/B3test/B3a/exampleB3a.cc:167

(Note that all my geometry is defined inside GDMLDetectorConstruction.hh - I know it is bad practice to write everything in the .hh file, but that is not the source of the error here. Relevant files are below (I call the reconstruction and cross-section generator from RunAction - which is where the “MPT Updated” cout is)
GDMLDetectorConstruction.hh (22.6 KB) CrossSectionTester.hh (14.9 KB) B3aRunAction.cc (7.6 KB)
I appreciate any help or advice.

Thank you.

Fixed it - turns out this error can be caused by bad pointer usage (even though that is unrelated to the error message!)