Visual C ++查找导致“调试断言失败”的行 [英] Visual C++ find line causing "Debug Assertion failed"

查看:1485
本文介绍了Visual C ++查找导致“调试断言失败”的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图获得一个C ++程序,它可以在使用gcc编译时正常工作,以在Visual C ++上正常工作。我的问题是,我现在得到以下错误:

 调试断言失败! 

程序:C:\ WINDOWS \ SYSTEM32 \ MSVCP110D.dll
文件:c:\程序文件(x86)\ microsoft visual studio 11.0 \ vc \ include \vector
行:1140

表达式:向量下标超出范围

我真正的问题是我不知道何时何地发生这种情况。通过在错误窗口中按下中断,我只被带到最终发生异常的向量类的部分。我想在我的应用程序中找到实际引起它的地方。我设法缩小到这个代码块:

  for(unsigned int i = 0; i< openPolygonList.size (); i ++)//在这里的某处出错
{
if(openPolygonList [i] .size()< 1)continue; (unsigned int j = 0; j< openPolygonList.size(); j ++)
{
if(openPolygonList [j] .size()< 1)

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 [i] .push_back(openPolygonList [j] [n] );

openPolygonList [j] .clear();
}
}
}
}

将brealpoints放置在使用矢量的每一行不是一个选项,因为循环重复数千次,并且每次按下continue都会花费我几个小时。有什么办法可以告诉调试器在错误发生时在适当的线路上制动,以便我可以检查变量并确定哪一个超出范围?

解决方案

我认为问题在于您正在擦除要迭代的向量的成员。如果你抹掉第一个元素会发生什么?

1 2 3
Ei v1 v2 v3



如果在i = 1时擦除1 ,我们的向量指数和值都低于现在的i = 2。

i 1 2
Ei v2 v3

最终,我认为你可以遍历该向量的末尾,导致你有一个指向该向量末尾的指针。完成猜测工作在这里,但可能有一个更简单的方法来做你想做的事情。我只是无法弄清楚你想要做什么。



看起来你试图在存储二维数组的同时颠倒行和列将对角线多边形排列成一个新数组。无论如何,是的,但在for循环的开始处是一个红色的圆圈,并逐行地遍历代码。



我会创建临时向量,然后修改for循环中的那些元素,然后替换向量openPolygonList。


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:

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 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:

    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 brealpoints 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 so that I can inspect the variables and determine which one is out of range?

解决方案

I think the problem is that you are erasing members of the vector you are iterating through. What happens if you erase the first element?

i 1 2 3 Ei v1 v2 v3

If we erase 1 when i = 1, our vector indices and values are below and now i = 2.

i 1 2 Ei v2 v3

Ultimately, I think you can iterate past the end of the vector causing you to have a pointer that points past the end of the vector. Complete guess work here, but there is probably an easier way to do what you're trying to do. I just can't figure out what you're trying to do.

It looks like you're trying to invert the rows and columns of a two dimensional array while storing the diagonal polygons int he array into a new array. Anyway, yes, but a red circle at the beginning of the for loop and walk through your code line by line.

I would create temp vectors and then modify those ones in the for loop and then replace the vector openPolygonList.

这篇关于Visual C ++查找导致“调试断言失败”的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆