Visual C ++ find string calling "Debug Assertion failed"

I am trying to get C ++ - a program that works great when compiling with gcc to work correctly in Visual C ++. My problem is that now I get the following error:

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 

My real problem is that I do not know when and where this happens. By clicking a break in the error window, I simply relate to the part of the vector class where the exception ultimately occurred. I want to find a place in my application that actually caused it. I managed to narrow it down to this code block:

  for(unsigned int i=0;i<openPolygonList.size();i++)//error somewhere in here { if (openPolygonList[i].size() < 1) continue; for(unsigned int j=0;j<openPolygonList.size();j++) { if (openPolygonList[j].size() < 1) continue; Point diff = openPolygonList[i][openPolygonList[i].size()-1] - openPolygonList[j][0]; int64_t distSquared = vSize2(diff); if (distSquared < 2 * 2) { if (i == j) { polygonList.push_back(openPolygonList[i]); openPolygonList.erase(openPolygonList.begin() + i); }else{ for(unsigned int n=0; n<openPolygonList[j].size(); n++) openPolygonList[i].push_back(openPolygonList[j][n]); openPolygonList[j].clear(); } } } } 

Simply placing drag points in each row where the vector is used is not an option, because the cycle repeats thousands of times and clicking the Continue button will literally take me for hours every time. Is there a way to tell the debugger about a stop on the corresponding line after an error occurs, so that I can check the variables and determine which one is out of range?

+4
source share
3 answers

I think the problem is that you are erasing the elements of the vector that you are executing. What happens if you delete the first item?

i 1 2 3 Ei v1 v2 v3

If we erase 1 with i = 1, our vector indices and values ​​are lower and now i = 2.

i 1 2 Ei v2 v3

In the end, I think you can repeat passing the end of the vector, forcing you to have a pointer that indicates the end of the vector. Complete guessing work here, but there is probably an easier way to do what you are trying to do. I just can't understand what you are trying to do.

It looks like you are trying to invert the rows and columns of a two-dimensional array while keeping the diagonal polygons inside the array in a new array. Anyway, yes, but the red circle is at the beginning of the for loop and go through your code line by line.

I would create temporary vectors and then change them in a for loop and replace the openPolygonList vector.

+3
source

The debugger cannot predict the future, but you can tell it to break all exceptions (ctrl + atl + e and mark all fields under "Thrown"). When the statement goes through the call stack to your code, it will tell you which line is causing the problem.

+3
source

You can open the call stack window (Debug-> windows-> CallStack) and find the location in your program that led to the statement. It should be 2 or 3 lines below the top line.

+2
source

Source: https://habr.com/ru/post/1487912/


All Articles