Segmentation fault

Hi ,

I am new root user. I have created a small program . it is a Garfield ++ program but uses root also.
I am getting Error : segmentation fault. The actual error is big but last section looks like this.

The lines below might hint at the cause of the crash.
If they do not help you then please submit a bug report at
http://root.cern.ch/bugs. Please post the ENTIRE stack trace
from above as an attachment in addition to anything else
that might help us fixing this issue.
===========================================================
#5  0x00007f9398ca708e in std::_Rb_tree<char const*, std::pair<char const* const, std::set<int, std::less<int>, std::allocator<int> > >, std::_Select1st<std::pair<char const* const, std::set<int, std::less<int>, std::allocator<int> > > >, NameMap::G__charptr_less, std::allocator<std::pair<char const* const, std::set<int, std::less<int>, std::allocator<int> > > > >::find(char const* const&) () from /usr/lib/x86_64-linux-gnu/libCint.so.5.34
===========================================================


Segmentation fault (core dumped)

My program is as follows:

#include <iostream>
#include <fstream>
#include <cmath>
#include "/home/varun/softwares/garfield++/Include/GeometrySimple.hh"
#include "/home/varun/softwares/garfield++/Include/SolidTube.hh"
#include "/home/varun/softwares/garfield++/Include/ViewGeometry.hh"
#include "/home/varun/softwares/garfield++/Include/MediumMagboltz.hh"
using namespace Garfield;
int main( int argc, char* argv[]){
        MediumGas* gas = new MediumGas();
	gas->LoadGasFile("ar_93_co2_7.gas");
	GeometrySimple* geo = new GeometrySimple();
	double rMin = 0., rMax = 0.5, halfLength = 10.;
	SolidTube* tube = new SolidTube(0., 0., 0., rMin, rMax, halfLength);
	geo->AddSolid(tube,gas);

	ViewGeometry* view = new ViewGeometry();
	view->SetGeometry(geo);
	view->Plot();

}

and my make file is like this:

OBJDIR = $(GARFIELD_HOME)/Object
SRCDIR = $(GARFIELD_HOME)/Source
INCDIR = $(GARFIELD_HOME)/Include
HEEDDIR = $(GARFIELD_HOME)/Heed
LIBDIR = $(GARFIELD_HOME)/Library

# Compiler flags
CXX = `root-config --cxx`
CFLAGS = `root-config --cflags` \
	-O3 -W -Wall -Wextra -Wno-long-long \
	-fno-common \
	-I$(INCDIR) -I$(HEEDDIR)

# Debug flags
# CFLAGS += -g

LDFLAGS = -L$(LIBDIR) -lGarfield
LDFLAGS += `root-config --glibs` -lGeom -lgfortran -lm

geo: geo.c
	$(CXX) $(CFLAGS) -c geo.c
	$(CXX) $(CFLAGS) -o geo geo.c $(LDFLAGS)
	rm geo.o

Make file compiles without error but when i run the executable i get the error.

Help is needed .

Dear Varun,

In your code, ROOT is used internally by the Garfield code. Your request should be addressed first to the Garfield support service, because they know how ROOT is used internally and may give hints or running examples.

As a first step, you should at least try to understand which line of your code gives the problem. And also post the complete error messages, as there may be other information meaningful to the persons giving support.

G Ganis

Hi ganis,

I have tried my best to understand the problem. But reading through the internet did not help.
I am new to c++. So i do not understand much of error in segmentation fault.

Here is my another program , and complete error msg. Program runs fine until it is asked to plot.
There is some issue with TeoGeoManager ( root class) and Viewcell ( Garfield ++ ) .


#include <iostream>
#include <fstream>
#include <cmath>
#include "TCanvas.h"
#include "MediumGas.hh"
#include "GeometrySimple.hh"
#include "SolidTube.hh"
#include "ViewCell.hh"
#include "ComponentAnalyticField.hh"

using namespace Garfield;

int main( int argc, char* argv[])
{

	MediumGas* gas = new MediumGas();
	gas->LoadGasFile("ar_93_c02_9.gas");
	gas->PrintGas();
	
	ComponentAnalyticField *cmp = new ComponentAnalyticField();
	GeometrySimple *geo = new GeometrySimple();
	double rMin = 0., rMax = 0.5, halfLength = 10.;
	SolidTube* tube = new SolidTube(0., 0., 0., rMin, rMax, halfLength);
	geo->AddSolid(tube, gas);
	geo->PrintSolids();
	cmp->SetGeometry(geo);
	const double vWire = 3270., vTube = 0.,  rWire = 25.e-4, rTube = 1.46;
	cmp->AddWire(0., 0., 2*rWire, vWire, "s");
	cmp->AddTube(rTube, vTube, 0, "t");
	
	ViewCell *view = new ViewCell();
	view->SetComponent(cmp);
	view->Plot3d();
}

Error Msg:


RandomEngineRoot:
    Generator type: TRandom3
    Seed: 2087288260
MediumGas::LoadGasFile:
   Gas file could not be opened.
MediumGas::PrintGas:
    Gas composition: Ar
    Pressure:    760 Torr
    Temperature: 293.15 K
    Gas file:
      Pressure:    760 Torr
      Temperature: 293.15 K
    Electric field range:  100 - 100000 V/cm in 19 steps.
    Magnetic field:        0
    Angle between E and B: 1.5708
    Available electron transport data:
      none
    Available ion transport data:
      none
GeometrySimple::PrintSolids:
    1 solid
      Index      Type    Medium
        0         tube     Ar
Info in <TGeoManager::TGeoManager>: Geometry ViewCellGeoManager, Cell Layout created
Info in <TGeoManager::SetTopVolume>: Top volume is World. Master volume is World
Info in <TGeoNavigator::BuildCache>: --- Maximum geometry depth set to 100

 *** Break *** segmentation violation



===========================================================
There was a crash.
This is the entire stack trace of all threads:
===========================================================
#0  0x00007f3c6b58eb4c in __libc_waitpid (pid=18044, stat_loc=stat_loc
entry=0x7fff533f6640, options=options
entry=0) at ../sysdeps/unix/sysv/linux/waitpid.c:31
#1  0x00007f3c6b5142e2 in do_system (line=<optimized out>) at ../sysdeps/posix/system.c:148
#2  0x00007f3c6d2e03a3 in TUnixSystem::StackTrace() () from /usr/lib/x86_64-linux-gnu/libCore.so
#3  0x00007f3c6d2e207c in TUnixSystem::DispatchSignals(ESignals) () from /usr/lib/x86_64-linux-gnu/libCore.so
#4  <signal handler called>
#5  0x0000000000456ebc in Garfield::ViewCell::Plot(bool) ()
#6  0x000000000045802c in Garfield::ViewCell::Plot3d() ()
#7  0x000000000040dddf in main ()
===========================================================


The lines below might hint at the cause of the crash.
If they do not help you then please submit a bug report at
[root.cern.ch/bugs](http://root.cern.ch/bugs). Please post the ENTIRE stack trace
from above as an attachment in addition to anything else
that might help us fixing this issue.
===========================================================
#5  0x0000000000456ebc in Garfield::ViewCell::Plot(bool) ()
#6  0x000000000045802c in Garfield::ViewCell::Plot3d() ()
#7  0x000000000040dddf in main ()
===========================================================


Segmentation fault (core dumped)


Any Suggestions ?

Hi,
usually a segmentation fault occurs when you try to access a region of memory in a not proper way; i.e., you declare an array with dimension 5 and try to access the 7th position.
I would suggest to put a lot of cout in your code, so you can find which method fails to execute.

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