title: mysterious segmentation fault in trivial C++ vector
body: <p>I want to assign values an vector p->vertexlist in this method in some iteration and has been memory problems when j= 3 and i = 2 (in the for iterations)</p>
  
  <pre><code>void py_tetgenio::set_facets(bp::list python_facets) {
  
  this-&gt;numberoffacets = bp::len(python_facets);
  this-&gt;facetlist = new tetgenio::facet[this-&gt;numberoffacets];
  this-&gt;facetmarkerlist = new int[this-&gt;numberoffacets];
  
  for (int i = 0; i &lt; this-&gt;numberoffacets; i++) {
      //iterar por sobre la lista agregando cada uno de los
      //identificadores a cada uno de los facets
      bp::list facet = bp::extract&lt;bp::list&gt;(python_facets[i]);
  
      tetgenio::facet *f = &amp;this-&gt;facetlist[i];
      f-&gt;numberofpolygons = 1;
      f-&gt;polygonlist = new tetgenio::polygon[f-&gt;numberofpolygons];
      f-&gt;numberofholes = 0;
      f-&gt;holelist = NULL;
      tetgenio::polygon *p = &amp;f-&gt;polygonlist[i];
  
      //iterar por sobre la lista de los id de los nodos
      //almacenados en la lista que representa al facets
  
      p-&gt;numberofvertices = bp::len(facet);
      p-&gt;vertexlist = new int[p-&gt;numberofvertices];
  
      for (int j = 0; j &lt; p-&gt;numberofvertices; j++) {
          int aux = bp::extract&lt;int&gt;(facet[j]);
          p-&gt;vertexlist[j] = aux; // SIGSEV:  Segmentation Fault!!! when j=3 
                                              // and i = 2
      }
      this-&gt;facetmarkerlist[i] = 1;
  }
  } //end set_facets
  </code></pre>
  
  <p>this is a <a href="http://www.youtube.com/watch?v=OwAG-DnWhiY" rel="nofollow">Mysterious</a></p>