Hello!
I have the following data structure declaration on which I make the following operation:
//QSweep.cpp
void QSweep:: createLoops(){
std:: vector< int > orientationUE;
if (test1)
orientationUE.push_back(1);
else
orientationUE.push_back(-1);
Everythink works fine so far. The problem is that I have several files and I want orientationUE to be a data of the class QSweep not only a local variable in the method createLoops(). So I added the declaration of the variable orientationUE in the file QSweep.h
//QSweep.h
class QSweep{
....
std::vector< int > orientationUE;
....
}
//QSweep.cpp
void QSweep:: createLoops(){
if (test1)
orientationUE.push_back(1);
else
orientationUE.push_back(-1);
}
In this case I obtain either a bus error message or a segmentation fault message depending on where I declared my variable orientationUE in the
class QSwepp{
....
}
I do not understand exactly what happens. Thanks in advance for any suggestions, madalina
ADD: Yes I have several memory allocation and several other declaration of variables of type vector (actually a lot). E.g.:
typedef Seq< vector<int> > MxInt2d;
class QSweep
{
public:
QSweep(){};
QSweep(const MxDouble2d& myPoints, const MxInt2d& myEdges);
void intersection();
//data and functions for inserting the missing edges in the graph
void completeGraph();
MxInt2d myEFCG;
std::vector< int > vNoClone;
std::vector< int > vEdge;
....
int nbIntersections;
MxInt2d sweepEvents;
std::vector<double*> myIntersections;
};
Still I have applied o lot of algorithms on these data types and I get the results without no segmentation fault or bus error message. So you think the error is somewhere in the other memory allocation jobs. Uff.. I was afraid of that. Still I do not understand the good results, they are misleading though? And how can I detect exactly the error in this case?
thanks.
ADD_NEXT:
The vector myIntersections is created in the following way:
double* QSweep::computeIntersection(double m1, double b1, double m2, double b2){
double* v=new double[3];
v[0]= (b2-b1)/(m1-m2);
v[1]= (m1*b2-m2*b1)/(m1-m2);
v[2]=0.00;
return v;
}
double* QSweepComplete::findIntersection(edge_t edge1, edge_t edge2){
double* vector=NULL;
if (test2){
return NULL;
}
else{
vector=computeIntersection(m1,b1,m2,b2);
return vector;
}
}
void QSweep:: intersection(){
double* vector=NULL;
vector=findIntersection(edge1,edge2);
if (vector!=NULL){
myIntersections.push_back(vector);
}
}
When I display the vector myIntersections everything is okay, plus that I always get the right size: if I have 5 intersections, 5 elements in the vector and so on. For me it looks quite clean, but unfortunately probably it isn't :(. thanks, madalina
ADD_LAST (MAYBE SOLVED): Hey everybody!
It seems the problem was the data
int nbIntersections;
which I only initialized it locally in a function in QSweep.cpp; Still, I am using a lot of vectors of the same size with nbIntersections, so the variable in some case contained some nonexistent datas. So I added to the constructor and initialized it with 0, and now it seems I have no problems anymore with the segmentation fault or bus error messages. I hope this was the mistake.
thanks, madalina