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. AtCoder Regular Contest 063 E:Integers on a Tree

    题目传送门:https://arc063.contest.atcoder.jp/tasks/arc063_c 题目翻译 给你一个树,上面有\(k\)个点有权值,问你是否能把剩下的\(n-k\)个点全部 ...

  2. es6 import 报错

    现在绝大多数的浏览器都不支持ES6,所以使用es6时需要使用bebal把es6转化为es5, 项目目录: demo1:单个js文件的转化 src文件下的 test1.js const aa=" ...

  3. ceph部署与问题

    一.基本情况:物理设备:4台惠普dl360,4个千兆网卡 4个1T盘操作系统统一为:CentOS 7.2.1511ceph版本:10.2.3ceph-deploy版本:1.5.36网络情况:192.1 ...

  4. bzoj4892

    后缀数组 先开始nc了,觉得自动机做法是指数级的,就写了个后缀数组 具体方法是暴力,枚举起点,然后用lcp向后暴力匹配,如果失配就减少一次,我们一共有3次机会,这样每次匹配复杂度是O(1)的,所以总复 ...

  5. Android开发--数据存储之数据库操作

    简介: SQLite 的介绍: SQLite数据库属于文本型的数据库,它是以文本的形式来保存的.Android提供了对 SQLite 数据库的完全支持,应用程序中的任何类都可以通过名称来访问任何的数据 ...

  6. C语言--递归问题

    1,一个经典的例子,理解递归过程的展开 #include<stdio.h> void func(int i){ ) func(i/); printf("%d",i) } ...

  7. Eclipse中实现JS代码提示功能

    转发: 用Eclipse写js代码时没有提示,很烦,心累: 找个各种方法以及插件,试了一下,个人感觉AngularJS Eclipse 插件很强,好用,不多说,先装上: 然后重启Eclipse ,右键 ...

  8. TextBox禁用与启用的方法

    $('#text1').textbox('enable');// 启用 $('#text1').textbox('disable');// 禁用 注:以上方法也适用于datebox等等

  9. MFC——ComBox用法大全

    Combo Box (组合框)控件很简单,可以节省空间.从用户角度来看,这个控件是由一个文本输入控件和一个下拉菜单组成的.用户可以从一个预先定义的列表里选择一个选项,同时也可以直接在文本框里面输入文本 ...

  10. 渲染路径-Deferred Lighting 延时光照

    http://blog.csdn.net/heyuchang666/article/details/51564954 注意: 最后3个步骤注意下 延时光照是有着最高保真度的光照和阴影的渲染路径.如果你 ...