调试断言失败:_CrtIsValidHeapPointer(pUserData) [英] Debug Assertion Failed: _CrtIsValidHeapPointer(pUserData)

查看:80
本文介绍了调试断言失败:_CrtIsValidHeapPointer(pUserData)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有时我在调试模式下运行我的 Qt 项目时遇到调试断言失败"错误(图像).我不知道我错在哪里,因为编译器什么也没说,我不知道该怎么做才能找到我的错误.

Sometimes I get this "Debug Assertion Failed" error running my Qt project in debug mode (image). I don't know where I wrong because the compiler says nothing and I don't know what to do to find my error.

我在 Windows Vista 下编程,使用 Qt Creator 2.4.1、Qt 4.8.1.

I program under Windows Vista, using Qt Creator 2.4.1, Qt 4.8.1.

我的程序必须从激光设备读取一些信息并将它们保存到一个文件中,代码类似于:

My program has to read some informations from a laser device and save them into a file with a code similar to this:

void runFunction()
{
    configure_Scanning(...);

    while(...)
    {
        // do something
        scanFunction();
        // do something
    }
}

这是我的有罪"功能(我认为问题出在哪里)

and this is my "incriminated" function (where I think the problem is)

void scanFunction()
{
    file.open();

    data = getDataFromDevice();

    if(flag)
    {
        if(QString::compare(lineB,"")!=0)
        {
            QTextStream out(&file);
            out << lineB << endl;
            lineB = "";
        }
        lineA.append(data+"	");
    }
    else
    {
        if(QString::compare(lineA,"")!=0)
        {
            QTextStream out(&file);
            out << lineA << endl;
            lineA = "";
        }
        lineB.prepend(data+"	");
    }

    file.close();
}

其中 lineAlineB 最初是两个无效的 QString:这个想法是我进行双向扫描以将信息保存在 2D 矩阵中(从 -X 到 +X反之亦然,而 Y 则前往指定目标).lineA 记住 (-) 到 (+) 的读数;lineB 记住 (+) 到 (-) 的读数.当扫描方向改变时,我将lineA(或lineB)写入文件并继续扫描.

Where lineA and lineB are initially two void QString: the idea is that I make a bidirectional scanning to save informations in a 2D matrix (from -X to +X and viceversa, while Y goes to a specified target). lineA memorizes the (-)to(+) reading; lineB memorizes the (+)to(-) reading. When the scanning direction changes, I write lineA (or lineB) to the file and I proceed with the scanning.

你明白我说的吗?你能给我建议一个解决方案吗?

Do you understand what I said? Could you suggest me a solution?

感谢和抱歉我的英语:P

Thanks and sorry for my English :P

推荐答案

_CrtIsValidHeapPointerUserData 意味着,您有一个堆损坏,调试堆检查器会注意到这一点.怀疑任何可以将任何信息写入任何已删除动态对象的人.是的,您不会在重写时立即收到堆损坏,而是在下一次堆检查时收到堆损坏,该检查将在任何下一次内存分配/释放时执行.然而,在单线程应用程序中应该通过调用堆栈进行简单的跟踪.

_CrtIsValidHeapPointerUserData means, that you have a heap corruption, which is noticed by debug heap checker. Suspect everybody who can write any information into any deleted dynamic object. And yes, you'll receive heap corruction not immideately on rewrite occurs, but on the next heap check, which will be performed on any next memory allocation/deallocation. However should be simply tracked by a call stack in single threaded applications.

这篇关于调试断言失败:_CrtIsValidHeapPointer(pUserData)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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