bus error/segmentation fault for std::vector<int> declaration
<p>I have the following data structure declaration on which I make the following operation:</p>

<pre><code>//QSweep.cpp
 void QSweep:: createLoops(){ 

 std:: vector&lt; int &gt; orientationUE;
 if (test1)
     orientationUE.push_back(1);
 else
     orientationUE.push_back(-1);
</code></pre>

<p>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</p>

<pre><code> //QSweep.h
 class QSweep{
    ....
    std::vector&lt; int &gt; orientationUE;
    ....
 }

 //QSweep.cpp
 void QSweep:: createLoops(){
    if (test1)
     orientationUE.push_back(1);
    else
     orientationUE.push_back(-1);
 }
</code></pre>

<p>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 </p>

<pre><code>  class QSwepp{
  ....
  }
</code></pre>

<p>I do not understand exactly what happens.
Thanks in advance for any suggestions,
madalina</p>

<p>ADD:
Yes I have several memory allocation and several other declaration of variables of type vector (actually a lot). E.g.:</p>

<pre><code>typedef Seq&lt; vector&lt;int&gt; &gt; MxInt2d;
class QSweep
{   
public:
  QSweep(){};
  QSweep(const MxDouble2d&amp; myPoints, const MxInt2d&amp; myEdges);
  void intersection();

  //data and functions for inserting the missing edges in the graph
  void completeGraph();   

  MxInt2d myEFCG;
  std::vector&lt; int &gt; vNoClone;
  std::vector&lt; int &gt; vEdge;

  ....

  int nbIntersections;
  MxInt2d sweepEvents;
  std::vector&lt;double*&gt; myIntersections;
};
</code></pre>

<p>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?</p>

<p>thanks.</p>

<p>ADD_NEXT:</p>

<p>The vector myIntersections is created in the following way:</p>

<pre><code> 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);
   }
 }
</code></pre>

<p>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</p>

<p>ADD_LAST (MAYBE SOLVED):
Hey everybody!</p>

<p>It seems the problem was the data </p>

<pre><code>    int nbIntersections;
</code></pre>

<p>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.</p>

<p>thanks,
madalina</p>
