title: Vector insert causes 'malloc(): invalid next size (unsorted)'
body: <p>I'm programming on my Raspberry Pi 3B+, with a Raspbian OS installed.</p>
  
  <p>I'm having trouble with this line of code:</p>
  
  <p><code>clusterPoints.insert(clusterPoints.begin(), cloudPtPointer);</code></p>
  
  <p>Where clusterPoints is a vector of the type cloudPoint pointer, that I created, and cloudPtPointer is the pointer to the cloudPoint that I want to insert. This is my cloudPoint struct:</p>
  
  <pre><code>struct cloudPoint {
      double realHeight;
      cv::Point3f point;
      cloudPoint* nextPoint;
  } ;
  </code></pre>
  
  <p>This code has been working for at least 2 weeks. Then I changed some stuff on another part of the project, and it started giving me this error </p>
  
  <blockquote>
    <p>"malloc(): invalid next size (unsorted)"</p>
  </blockquote>
  
  <p>This error doesn't occur in the first 8 times that line of code is executed. I checked my variables, memory address and vector, and everything is working as intended, but I can't figure out what's causing a memory corruption. </p>
  
  <hr>
  
  <p>EDIT:
  I cannot paste my code, but this are the lines of code that use/have influence on the vector. Sorry in advance for this, but its the only way I can provide you more information. The code has a while (loop 4#) inside a for(loop #3) inside a for(loop #2) inside a for (loop # 1). Loop #2 and #3 are used to go through a 2d map, and Loop 4# is used to add all connected points to a vector:</p>
  
  <pre><code>std::vector&lt;cloudPoint*&gt; clusterPoints;  --&gt; In the beggining of the function
  clusterPoints.clear();                   --&gt; In the beggining of Loop #1
  clusterPoints.insert(clusterPoints.begin(), cloudPtPointer); --&gt; At Loop 3#
  clusterPoints.insert(clusterPoints.begin(), connectedPointsSet.begin(), connectedPointsSet.end()); ---&gt; after Loop #4 (inside loop #3).
  </code></pre>
  
  <p>That connectedPointsSet, is a vector of cloudPoints. To construct that vector I  push back a set of points that are pointing to the next point, until there's nothing pointing to. </p>
  
  <hr>
  
  <p>EDIT 2:</p>
  
  <p>The change that caused the error was in 2 functions. I had to change its headers so the date type would be compatible. This are the old headers:</p>
  
  <pre><code>std::vector&lt;Segmentation::cloudPoint&gt;build2DTo3D(cv::Mat&amp;);
  bool transform2GlobalRef(std::vector&lt;cv::Point3f&gt;&amp;);
  </code></pre>
  
  <p>And This are the new ones:</p>
  
  <pre><code>std::vector&lt;cv::Point3f&gt; build2DTo3D(cv::Mat&amp;);
  std::vector&lt;Segmentation::cloudPoint&gt; transform2GlobalRef(std::vector&lt;cv::Point3f&gt;&amp;)
  </code></pre>