MFC 应用程序在关闭时崩溃
我有一个正在运行的 MFC 应用程序(一个对话框应用程序),我删除了它的一些按钮并添加了一个新按钮,但现在当它关闭时,应用程序崩溃了。它在 ASSERT() 宏之一中失败。调试断言在这些行上失败
文件:afxtempl.h 行:558
当我查看该代码时,它是这样的 有
template<class TYPE, class ARG_TYPE>
void CArray<TYPE, ARG_TYPE>::AssertValid() const
{
CObject::AssertValid();
if (m_pData == NULL)
{
ASSERT(m_nSize == 0);
ASSERT(m_nMaxSize == 0);
}
else
{
// here it fails
ASSERT(m_nSize >= 0);
ASSERT(m_nMaxSize >= 0);
ASSERT(m_nSize <= m_nMaxSize);
ASSERT(AfxIsValidAddress(m_pData, m_nMaxSize * sizeof(TYPE)));
}
}
#endif //_DEBUG
任何线索表明出了什么问题吗?该应用程序早些时候运行良好,但我搞砸了。
I had a working MFC application (a dialog application), I deleted some of its button and added a new button, but now when it closes the application crashes. It fails in one of ASSERT() macro. The debug assertions fails on these lines
File: afxtempl.h
Line: 558
When I view that code it was something like this
template<class TYPE, class ARG_TYPE>
void CArray<TYPE, ARG_TYPE>::AssertValid() const
{
CObject::AssertValid();
if (m_pData == NULL)
{
ASSERT(m_nSize == 0);
ASSERT(m_nMaxSize == 0);
}
else
{
// here it fails
ASSERT(m_nSize >= 0);
ASSERT(m_nMaxSize >= 0);
ASSERT(m_nSize <= m_nMaxSize);
ASSERT(AfxIsValidAddress(m_pData, m_nMaxSize * sizeof(TYPE)));
}
}
#endif //_DEBUG
Any clues as to what is going wrong? The application was working fine when earlier, but I messed it up.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我想查看导致断言的堆栈跟踪中的内容 - 以及各个成员变量中的内容。例如,如果原因是双重删除,则在调试版本中,您会期望在值中看到值 0xdddddddd,因为调试分配器将释放的内存设置为此值。
I'd want to see what is in the stack trace leading up to the assertion - also what is in the various member variables. For example, if the cause is a double deletion, in a debug build you would expect to see the value 0xdddddddd in the value since the debug allocator sets freed memory to this value.
当我无意中在
resource.h
中定义了重复的资源 id 时,我就遇到过这样疯狂的事情。如果您唯一更改的是添加/删除一些按钮,我会首先检查这一点,然后尝试完全重建。I've see crazy things like this when I've inadvertently got duplicate resource ids defined in
resource.h
. If the only thing you've changed is add/remove a few buttons, I would check this first then try a full rebuild.几个月前,我遇到了同样的问题 - MFC 在关闭时崩溃。后来发现在析构函数中我试图删除或释放一些已经删除的内存,但不知何故通过了它之前的空检查。也许你可以检查这一点。
Few months ago I have the same kind of problem - MFC crash on closing. Later found that in a destructor I was trying to delete or free some memory which is already deleted but somehow passing the null checking before it.May be you can check this point.