# Segmentation fault when use ViewGeometry::Plot3d()

**URL:** <https://root-forum.cern.ch/t/segmentation-fault-when-use-viewgeometry-plot3d/47730>\
**Category:** Garfield++\
**Created:** [November 19, 2021, 5:30am UTC](https://root-forum.cern.ch/t/segmentation-fault-when-use-viewgeometry-plot3d/47730 "2021-11-19T05:30:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Crisps](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/crisps/32/39101_2.png) [@Crisps](https://root-forum.cern.ch/u/Crisps)\
**Post date:** [November 19, 2021, 5:30am UTC](https://root-forum.cern.ch/t/segmentation-fault-when-use-viewgeometry-plot3d/47730/1 "2021-11-19T05:30:46Z")

</div>

Dear experts,

I was trying to set a geometry of my simple prototype of a drift chamber, using GeometrySimple and SolidBox. Also I filled He/IC4H10 for 90/10 by MediumMagboltz. It seems all fine with doing above, but I got a segmentation fault when I add the function ViewGeometry::Plot3d(). Please give me some advise where is the problem. Thanks in advance!

```auto
void SetupGeo(TString geomFile){
  fGeo = new GeometrySimple();
  
  SolidBox *box = new SolidBox(0,0,0,10,10,fSize_box/2);
  fGeo->AddSolid(box, fGas);

  fCompE_Field = new ComponentAnalyticField();
  fCompE_Field->SetGeometry(fGeo);

  const int senseHV = fHV;
  const int fieldHV = 0;

  TFile *ifile = new TFile(geomfile);
  TTree *itree = (TTree*)ifile->Get("t");
  double x,y;
  int type;
  itree->SetBranchAddress("x",&x);
  itree->SetBranchAddress("y",&y);
  itree->SetBranchAddress("type",&type);
  for (int i = 0; i<itree->GetEntries(); i++){
    itree->GetEntry(i);
    if (type==0){ // field wire
      fCompE_Field->AddWire( x, y, d_field, fieldHV, Form("f%d",i), 147.42);
    }
    else if (type==1){ // sense wire
      fCompE_Field->AddWire( x, y, d_sense, senseHV, Form("s%d",i), 147.42);
      fCompE_Field->AddReadout(Form("s%d",i));
      }
    }

  fCompE_Field->SetMagneticField(0,0,0);

  //view geometry
  ViewGeometry *geoView;
  geoView->SetGeometry(fGeo);
  geoView->Plot3d();
}

```

---

<div class="post-metadata">

**Author:** ![hschindl](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/h/977dab/32.png) [@hschindl](https://root-forum.cern.ch/u/hschindl)\
**Post date:** [November 19, 2021, 6:33am UTC](https://root-forum.cern.ch/t/segmentation-fault-when-use-viewgeometry-plot3d/47730/2 "2021-11-19T06:33:01Z")

</div>

I think the problem is with this line

```auto
ViewGeometry *geoView;

```

which should probably read

```auto
ViewGeometry *geoView = new ViewGeometry();

```

Alternatively, you could write

```auto
ViewGeometry geoView;
geoView.SetGeometry(fGeo);
geoView.Plot3d();

```

---

<div class="post-metadata">

**Author:** ![system](https://root-forum.cern.ch/uploads/default/original/3X/e/f/efe4f24398fd8ffeb76bccb6ecc46d9d9c003376.png) [@system](https://root-forum.cern.ch/u/system)\
**Post date:** [December 3, 2021, 6:33am UTC](https://root-forum.cern.ch/t/segmentation-fault-when-use-viewgeometry-plot3d/47730/3 "2021-12-03T06:33:35Z")

</div>

Closed on December 3, 2021, 6:33am UTC

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
