title: Vector insert crashes program
body: <p>Can anyone tell me</p>
  
  <p>why this crashes my program? It's suppose to make it so order has all the elements in the t vector situated by (y + height).</p>
  
  <p>Edit: crashes on the lines with "insert" in them.</p>
  
  <pre><code>void createDrawOrder(vector&lt;Thing*&gt; t, vector&lt;int&gt; *order) {
          int min = t[0]-&gt;y + t[0]-&gt;height;
          int max = t[0]-&gt;y + t[0]-&gt;height;
  
          vector&lt;int&gt;::iterator it;
  
          it = order-&gt;begin();
  
          order-&gt;push_back(0);
  
          for (int i = 1; i &lt; (int) t.size(); i++) {
              if ((t[i]-&gt;y  + t[i]-&gt;height) &lt; min) {
                  min = (t[i]-&gt;y  + t[i]-&gt;height);
                  order-&gt;insert(it, i);
              }
  
              else if((t[i]-&gt;y + t[i]-&gt;height) &gt;= min &amp;&amp; (t[i]-&gt;y + t[i]-&gt;height) &lt; max){
  
                  int tempsize = (int) order-&gt;size();
  
                  for (int j = 0; j &lt; tempsize; j++){
                      if((t[i]-&gt;y + t[i]-&gt;height) &lt;= (t[(*order)[j]]-&gt;y + t[(*order)[j]]-&gt;height)){
                              order-&gt;insert(it + j, i);
                      }
                  }
              }
  
              else if ((t[i]-&gt;y + t[i]-&gt;height) &gt;= max) {
                  max = (t[i]-&gt;y + t[i]-&gt;height);
                  order-&gt;push_back(i);
              }
          }
  
      }//end method max
  </code></pre>