I'm writing a C++ MFC program on VS2008 and I'm getting this "Debug Assertion Error" when I first run the program sometimes. When I try to debug it, it takes me to this winhand.cpp file which is not part of the program I wrote so I'm not sure how to debug this.

It takes the error to this place in winhand.cpp

 CObject* pTemp = LookupTemporary(h);
if (pTemp != NULL)
{
// temporary objects must have correct handle values
HANDLE* ph = (HANDLE*)((BYTE*)pTemp + m_nOffset); // after CObject
ASSERT(ph[0] == h || ph[0] == NULL);
if (m_nHandles == 2)
ASSERT(ph[1] == h);
}

  

So why does this error happen? Why does it only happen sometimes (50% of the time)? How would I debug this?

I'll provide some code if is needed.

THANKS!

Answers

The code that is asserting is part of MFC's CHandleMap class. MFC deals with windows as CWndobjects, but Windows deals with them as HWND handles. the handle map allows MFC to 'convert' anHWND into a pointer to the MFC object representing that object.

What the assertion seems to be doing is checking that when a lookup of the handle finds an MFC object, that the MFC object also thinks it's wrapping the same handle.

If they're different, then you get the assertion.

So it would appear that something is corrupting the handle map or the MFC object for that handle or you're doing something incorrect that gets these 2 data structures out of sync.

Some things you might do to try to debug the problem is to determine:

  • what MFC object is being found in the lookup (that's what's being pointed to by pObject)
  • what the MFC object thinks it's wrapping (that's the handle ph[0] and/or ph[1] - I'm not sure why there can be 2 of them)
  • what the handle is for (that's h)

Do the handles look like handle values or do they look like garbage? Does pObject point to something that looks like an MFC object, or garbage? Do any of these these things seem related?

The answers to these questions may point to what you need to do next (maybe set a debug write breakpoint on the item that looks like it's trashed).

我在coding的时候也遇到这个问题了,后来找到了出错语句:

((COutPutDlg*)GetParent())->m_CurIndex=m_CurIndex;

  上面语句所在的类CPreviewDlg的对象窗体本来处于类COutPutDlg对象窗体之上,即前者是后者的子窗体,后来我使用语句:

SetParent(GetDesktopWindow()); 

该语句改变了CPreviewDlg对象的父窗体,改变后,调用((COutPutDlg*)GetParent())->m_CurIndex=m_CurIndex;并不会报错,但是在程序退出的时候,就出现了“Debug Assertion” Runtime Error。

原因好像就是上文中说的对应关系被破坏了,不是很了解,还有其他事,暂且放一放。

“Debug Assertion” Runtime Error on VS2008 VS2010 winhand.cpp的更多相关文章

  1. Solve Error Debug Assertion Failed Expression vector iterators incompatible Using PCL in Release Mode of VS2010

    When using PCL 1.4.0 in the release mode building under VS2010, we might sometime get the error &quo ...

  2. C++ error:Debug Assertion Failed.Expression:_BLOCK_TYPE_IS_VALID(phead->nBlock)

    Debug Assertion Failed.Expression:_BLOCK_TYPE_IS_VALID(phead->nBlockUse) 关于上面这个错误,我在上一篇文章中的程序遇到过了 ...

  3. Qt Sqlite qwt 发布过程中碰到的问题runtime error

    qt版本:4.8.0 qwt版本:6.1.2 使用dll show检测缺少的dll,或者笨一点的方法,点击运行差什么找什么放进去: 左上显示exe调用哪些dll,右边是dll又再次调用啦哪些dll: ...

  4. Qt 调试时的错误——Debug Assertion Failed!

    在VS2008中写qt程序时调试出现此问题,但在release模式下就不存在,在网上搜罗了一圈,是指针的问题. 问题是这样的: 需要打开两个文件,文件中数据类型是float,我使用QVector进行保 ...

  5. Microsoft Visual C++ Runtime Library Runtime Error的解决的方法

    打开浏览器时,出现Microsoft Visual C++ Runtime Library Runtime Error错误,初步预计是软件冲突,可能有多种出错的方式,我的是浏览器自己主动关闭. 一. ...

  6. Microsoft Visual C++ Runtime Library Runtime Error解决的方式

    打开浏览器时,出现Microsoft Visual C++ Runtime Library Runtime Error错误,初步预计是软件冲突,可能有多种出错的方式,我的是浏览器自己主动关闭. 一. ...

  7. C Run-Time Error R6034问题的解决

    1.问题描述 这两天一直在用vs2008编写一个小项目,需要在c++代码中通过命令行的方式调用cl.exe和link.exe,也就是给编译器cl和链接器link传递参数,然后编译链接生成可执行文件ex ...

  8. opencv 3.2 vs2015 debug assertion __acrt_first_block == header

    网上复制了一个转直方图的代码 ,说来也奇怪, 用imshow 显示 图片在独立窗体内,不存在问题, 要注释掉这段代码就出现了下边的错误. 网上查了查,原来是程序中 有个std::vector<c ...

  9. Runtime Error R6034 Application has attempt to load the C runtime library incorrectly

    1.问题描述 vs2015 去开发一个写入pg数据库的程序,使用libpqxx.dll,libpq.dll,这个库文件之前是用vs2008的程序中复制过来的,基于的运行时库应该是vs2008,现在开发 ...

随机推荐

  1. SQL 电子书

    http://vdisk.weibo.com/search/?type=&sortby=default&keyword=SQL+Server&filetype=&pag ...

  2. SQL Server 盛宴系列 webcast

    数据库学习站点,示例,视频 http://technet.microsoft.com/zh-cn/dd722671.aspx

  3. Kmeans算法--python实现

    一:Kmeans算法基本思想: k-means算法是一种很常见的聚类算法,它的基本思想是:通过迭代寻找k个聚类的一种划分方案,使得用这k个聚类的均值来代表相应各类样本时所得的总体误差最小. k-mea ...

  4. hdu-2563

    统计问题 Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submis ...

  5. g2o扩展,然后重新编译生成新库。

    orb作者有g2o扩展,g2o原作者也有g2o扩展,等各项基本功扎实以后,考虑把他们整合在一起,再加上高博扩展的g2o,统一cmake,make,然后能make install 正常使用,就最好了.

  6. spown mj

    local function getmjvalnew(key) local keynew = {} local sumnval = 0 for _, v in ipairs(key) do if v& ...

  7. liteos任务(二)

    任务 1 基本概念 从系统的角度看,任务是竞争系统资源的最小运行单元.任务可以使用或等待CPU.使用内存空间等系统资源,并独立于其它任务运行. Huawei LiteOS的任务模块可以给用户提供多个任 ...

  8. python接口自动化(三十七)-封装与调用--读取excel 数据(详解)

    简介 在进行软件接口测试或设计自动化测试框架时,一个不比可避免的过程就是: 参数化,在利用python进行自动化测试开发时,通常会使用excel来做数据管理,利用xlrd.xlwt开源包来读写exce ...

  9. 让webStorm支持自动监听编译scss文件

    前提概要 今日,重装了两波系统,,,之前安装的各种环境都忘光了,重新又踩一次坑的感觉很不舒服,所以记录一下配置自动编译scss一路遇到的坑 一.webstrom run的时候控制台输出的错误中文提示乱 ...

  10. uoj#275. 【清华集训2016】组合数问题(数位dp)

    传送门 假设有\(k|{n\choose m}\),因为\(n!\)中质因子\(k\)的次数为\(S(n)=\left\lfloor\frac{n}{k}\right\rfloor+\left\lfl ...