title: Visual C++ find line causing "Debug Assertion failed"
body: <p>I am trying to get a C++ program that works fine when compiled with gcc to work properly on Visual C++. My problem is that I am now getting the following error:</p>
  
  <pre><code>Debug Assertion Failed!
  
  Program: C:\WINDOWS\SYSTEM32\MSVCP110D.dll
  File: c:\program files (x86)\microsoft visual studio 11.0\vc\include\vector
  Line: 1140
  
  Expression: vector subscript out of range
  </code></pre>
  
  <p>My real problem is that I do not know when or where this happens. By pressing break in the error window I am merely taken to the part of the vector class where the exception ultimately happened. I want to find the place in my application which actually caused it. I have managed to narrow it down to this block of code:</p>
  
  <pre><code>    for(unsigned int i=0;i&lt;openPolygonList.size();i++)//error somewhere in here
      {
          if (openPolygonList[i].size() &lt; 1) continue;
          for(unsigned int j=0;j&lt;openPolygonList.size();j++)
          {
              if (openPolygonList[j].size() &lt; 1) continue;
  
              Point diff = openPolygonList[i][openPolygonList[i].size()-1] - openPolygonList[j][0];
              int64_t distSquared = vSize2(diff);
  
              if (distSquared &lt; 2 * 2)
              {
                  if (i == j)
                  {
                      polygonList.push_back(openPolygonList[i]);
                      openPolygonList.erase(openPolygonList.begin() + i);
                  }else{
                      for(unsigned int n=0; n&lt;openPolygonList[j].size(); n++)
                          openPolygonList[i].push_back(openPolygonList[j][n]);
  
                      openPolygonList[j].clear();
                  }
              }
          }
      }
  </code></pre>
  
  <p>Simply placing breakpoints at each line where a vector is used is not an option because the loop iterates thousands of times and having to press continue each time will literally take me hours. Is there any way I can tell the debugger to brake on the appropriate line once the error occurs. It can help me to inspect the variables and to determine which variable is out of range?  </p>