vs mfc编程中意外出现Debug Assertion Failed
** 今天进行mfc编程中意外出现Debug Assertion Failed错误,网上搜也没解决,最后发现是在创建接收客户机连接线程函数中使用了UpdateData(true);出错的原因**
触发断点处在wincore.cpp的文件中:
if(pMap) { ASSERT( (p = pMap->LookupPermanent(m_hWnd)) != NULL || (p = pMap->LookupTemporary(m_hWnd)) != NULL); } ASSERT((CWnd*)p == this); // must be us
看的一篇博客说是跨线程访问UI元素造成的。微软具体说明:
In a multi-threaded application written using MFC, you should not pass MFC objects across thread boundaries. As a general rule, a thread should access only those MFC objects that it creates. Failure to do so may cause run-time problems including assertions or unexpected program behavior.
//在使用MFC编写的多线程应用程序中,不应跨越线程边界传递MFC对象。 通常,线程应仅访问其创建的MFC对象。 否则可能会导致运行时问题,包括断言或程序意外行为。
最后在函数中把UpdateData(true)去掉即可正常运行;
参考博客:https://blog.csdn.net/txk15619567977/article/details/17786101

浙公网安备 33010602011771号