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. iOS 中这些是否熟练掌握——(1)

    声明:本篇博文是作者原创作品.参考1  参考2  参考3  参考4  参考5  参考6 关于网上一些关于iOS资料,自己通过学习做了一些整理,这里仅仅作为笔记,方便自己学习使用,加深理解. 1.什么是 ...

  2. vs未能正确加载XX包的解决方法

    管理员 -- cmd ---(进入到vs的安装目录下.如我的是:C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE)---d ...

  3. python数据分析笔记中panda(3)

    1 按照空格将一列的内容分为两列 from pandas import Series; from pandas import DataFrame; from pandas import read_cs ...

  4. 网络编程-http连接-GET&POST

    GetRequest package com.net.http; import java.io.BufferedReader; import java.io.IOException; import j ...

  5. 洛谷 - P2281 - 多项式的加法和乘法 - 大模拟

    题目链接:https://www.luogu.org/problemnew/show/P2281 题目的意思很简单,输入两个系数.指数都是整数,变量都是大写字母的多项式,求他们的加法结果和乘法结果. ...

  6. HDU2824【欧拉函数性质】

    思路: 打表. 利用公式. 类似素数打表一样. #include<bits/stdc++.h> using namespace std; const int N=3e6+10; bool ...

  7. Java内存模型(Java Memory Model,JMM)

    今天简单聊聊什么叫做 Java 内存模型,不是 JVM 内存结构哦. JMM 是一个语言级别的内存模型,处理器的硬件模型是硬件级别,Java中的内存模型是内存可见性的基本保证.从而为我们 volati ...

  8. 康少带你python项目从部署到上线云服务器

    首先,服务器要安装nginx和mysql,网站文件建议放在/usr/local/www,环境python3.6+mysql5.7,阿里云的服务器可以用公共镜像有一个配置好的,不然就自己装一下环境吧. ...

  9. IT兄弟连 JavaWeb教程 Cookie和Session应用结合使用

    一般对于不要求安全的非敏感数据,建议存储在Cookie中! 对于敏感的数据,占用空间较小的,建议存储在Session中! 对于敏感的,较大的数据,存数据库!

  10. SpringBoot 2.0 集成 JavaMail ,实现异步发送邮件

    一.JavaMail的核心API 1.API功能图解 2.API说明 (1).Message 类: javax.mail.Message 类是创建和解析邮件的一个抽象类 子类javax.mail.in ...