我现在因使用带有最新工具集的VS2017重建我的程序而获得访问冲突 - 当关闭程序时

时间:2018-01-21 21:48:32

标签: mfc visual-studio-2017

我刚刚遇到一个我不知道如何解决的问题。我有一个MDI应用程序,我从2002年开始,从那时起一直在进行。

我在VS2017中第一次重建它(使用最新的工具集),除了我关闭程序之外,它们似乎都很好。引发了一个例外,它带我进入VS2017 IDE:

Exception

真的很混乱。堆栈跟踪:

>   [Inline Frame] CommunityTalks_x64.exe!ATL::CImage::CInitGDIPlus::ReleaseGDIPlus() Line 583  C++ Symbols loaded.
    [Inline Frame] CommunityTalks_x64.exe!ATL::CImage::CInitGDIPlus::{dtor}() Line 555  C++ Symbols loaded.
    CommunityTalks_x64.exe!`ATL::CImage::GetInitGDIPlusInstance'::`2'::`dynamic atexit destructor for 'gdiPlus''()  C++ Symbols loaded.
    CommunityTalks_x64.exe!_execute_onexit_table::__l2::<lambda>() Line 206 C++ Symbols loaded.
    CommunityTalks_x64.exe!__crt_seh_guarded_call<int>::operator()<void <lambda>(void),int <lambda>(void) & __ptr64,void <lambda>(void) >(__acrt_lock_and_call::__l2::void <lambda>(void) && setup, _execute_onexit_table::__l2::int <lambda>(void) & action, __acrt_lock_and_call::__l2::void <lambda>(void) && cleanup) Line 204  C++ Symbols loaded.
    [Inline Frame] CommunityTalks_x64.exe!__acrt_lock_and_call(const __acrt_lock_id) Line 936   C++ Symbols loaded.
    CommunityTalks_x64.exe!_execute_onexit_table(_onexit_table_t * table) Line 231  C++ Symbols loaded.
    CommunityTalks_x64.exe!common_exit::__l2::<lambda>() Line 230   C++ Symbols loaded.
    CommunityTalks_x64.exe!__crt_seh_guarded_call<void>::operator()<void <lambda>(void),void <lambda>(void) & __ptr64,void <lambda>(void) >(__acrt_lock_and_call::__l2::void <lambda>(void) && setup, common_exit::__l2::void <lambda>(void) & action, __acrt_lock_and_call::__l2::void <lambda>(void) && cleanup) Line 224 C++ Symbols loaded.
    [Inline Frame] CommunityTalks_x64.exe!__acrt_lock_and_call(const __acrt_lock_id) Line 936   C++ Symbols loaded.
    CommunityTalks_x64.exe!common_exit(const int return_code, const _crt_exit_cleanup_mode cleanup_mode, const _crt_exit_return_mode return_mode) Line 278  C++ Symbols loaded.
    CommunityTalks_x64.exe!__scrt_common_main_seh() Line 290    C++ Symbols loaded.
    kernel32.dll!00007ffcd5301fe4() Unknown No symbols loaded.
    ntdll.dll!00007ffcd71defb1()    Unknown No symbols loaded.

它触发的代码:

inline void CImage::CInitGDIPlus::ReleaseGDIPlus() throw()
{
    EnterCriticalSection(&m_sect);
    if( m_dwToken != 0 )
    {
        Gdiplus::GdiplusShutdown( m_dwToken );
    }
    m_dwToken = 0;
    LeaveCriticalSection(&m_sect);
}

这不是我的个人代码,我不知道发生了什么。我的输出日志:

The thread 0x2c50 has exited with code 0 (0x0).
'CommunityTalks_x64.exe' (Win32): Unloaded 'C:\Windows\System32\userenv.dll'
'CommunityTalks_x64.exe' (Win32): Unloaded 'C:\Windows\System32\d3d10warp.dll'
Exception thrown at 0x00007FFCD35E3FB8 (KernelBase.dll) in CommunityTalks_x64.exe: 0x0000071A: The remote procedure call was canceled, or if a call time-out was specified, the call timed out.
The thread 0x960 has exited with code 0 (0x0).
The thread 0xd84 has exited with code 0 (0x0).
The thread 0x8dc has exited with code 0 (0x0).
The thread 0x1270 has exited with code 0 (0x0).
The thread 0x33c has exited with code 0 (0x0).
The thread 0x2308 has exited with code 0 (0x0).
The thread 0x53c has exited with code 0 (0x0).
The thread 0x20c0 has exited with code 0 (0x0).
Exception thrown at 0x00007FFCD71BBE6B (ntdll.dll) in CommunityTalks_x64.exe: 0xC0000005: Access violation writing location 0x0000000000000024.

The program '[2204] CommunityTalks_x64.exe' has exited with code 0 (0x0).

我不知道发生了什么,我不得不停止调试过程。

我在这里深处,我不知道该怎么做。

更新

我偶然发现了这个:

https://developercommunity.visualstudio.com/content/problem/173633/mfc-library-big-bug.html

更新2

我尝试根据评论中的建议放置断点,但异常已经触发。我在这里被引导到一个相关的问题:

https://developercommunity.visualstudio.com/content/problem/169288/vc2017-1552-mfc-library-big-bug.html

其中一个解决方案是:

  

作为解决方法,请尝试禁用threadSafeInit:add / Zc:threadSafeInit- C ++编译器选项) - 它应该解决问题。

我刚刚更改了设置,现在异常没有发生。我也查了/Zc:threadSafeInit,但这完全是我的头脑。我所知道的是我之前没有遇到任何问题。除非我添加此开关,否则dbeugger始终会导致异常。

这有多重要?可以按照这种方法进行解决吗?

更新3

我关闭了WindowsBlinds只是因为它正在进行干扰并在此方法中使用断点进行调试跟踪:

inline bool CImage::CInitGDIPlus::Init() throw()

有趣的是,这会被拦截,仔细检查这里是堆栈:

    CommunityTalks_x64.exe!ATL::CImage::CInitGDIPlus::Init() Line 573   C++ Symbols loaded.
    [Inline Frame] CommunityTalks_x64.exe!ATL::CImage::InitGDIPlus() Line 2075  C++ Symbols loaded.
    CommunityTalks_x64.exe!ATL::CImage::Load(IStream * pStream) Line 1376   C++ Symbols loaded.
>   CommunityTalks_x64.exe!CPngImage::LoadFromBuffer(unsigned char * lpBuffer, unsigned int uiSize) Line 4057   C++ Symbols loaded.
    CommunityTalks_x64.exe!CPngImage::Load(const wchar_t * lpszResourceName, HINSTANCE__ * hinstRes) Line 3986  C++ Symbols loaded.
    CommunityTalks_x64.exe!CMFCToolBarImages::LoadStr(const wchar_t * lpszResourceName, HINSTANCE__ * hinstRes, int bAdd) Line 942  C++ Symbols loaded.
    CommunityTalks_x64.exe!CMFCRibbonInfoLoader::LoadImageW(const CMFCRibbonInfo::XID & id, CMFCToolBarImages & image, int bSingle) Line 150    C++ Symbols loaded.
    CommunityTalks_x64.exe!CMFCRibbonInfoLoader::LoadImageW(CMFCRibbonInfo::XImage & image, int bSingle) Line 199   C++ Symbols loaded.
    CommunityTalks_x64.exe!CMFCRibbonInfoLoader::LoadFromBuffer(unsigned char * lpBuffer, unsigned int nSize) Line 124  C++ Symbols loaded.
    CommunityTalks_x64.exe!CMFCRibbonInfoLoader::Load(const wchar_t * lpszResID, const wchar_t * lpszResType, HINSTANCE__ * hInstance) Line 88  C++ Symbols loaded.
    CommunityTalks_x64.exe!CMFCRibbonBar::LoadFromResource(const wchar_t * lpszXMLResID, const wchar_t * lpszResType, HINSTANCE__ * hInstance) Line 1146    C++ Symbols loaded.
    CommunityTalks_x64.exe!CMainFrame::OnCreate(tagCREATESTRUCTW * lpCreateStruct) Line 298 C++ Symbols loaded.
    CommunityTalks_x64.exe!CWnd::OnWndMsg(unsigned int message, unsigned __int64 wParam, __int64 lParam, __int64 * pResult) Line 2292   C++ Symbols loaded.
    CommunityTalks_x64.exe!CWnd::WindowProc(unsigned int message, unsigned __int64 wParam, __int64 lParam) Line 2099    C++ Symbols loaded.
    CommunityTalks_x64.exe!AfxCallWndProc(CWnd * pWnd, HWND__ * hWnd, unsigned int nMsg, unsigned __int64 wParam, __int64 lParam) Line 265  C++ Symbols loaded.
    CommunityTalks_x64.exe!AfxWndProc(HWND__ * hWnd, unsigned int nMsg, unsigned __int64 wParam, __int64 lParam) Line 417   C+

+   Symbols loaded.

CMFCToolBarImages::LoadStr方法有以下代码:

// Try to load PNG image first:
CPngImage pngImage;
if (pngImage.Load(lpszResourceName, hinstRes))
{
    hbmp = (HBITMAP) pngImage.Detach();
}
else

此代码if (pngImage.Load(lpszResourceName, hinstRes))调用:

BOOL bRes = LoadFromBuffer((LPBYTE) lpBuffer, (UINT) ::SizeofResource(hinstRes, hRsrc));

LoadFromBuffer来电是这样的:

BOOL CPngImage::LoadFromBuffer(LPBYTE lpBuffer, UINT uiSize)
{
    ASSERT(lpBuffer != NULL);

    HGLOBAL hRes = ::GlobalAlloc(GMEM_MOVEABLE, uiSize);
    if (hRes == NULL)
    {
        return FALSE;
    }

    IStream* pStream = NULL;
    LPVOID lpResBuffer = ::GlobalLock(hRes);
    ASSERT (lpResBuffer != NULL);

    memcpy(lpResBuffer, lpBuffer, uiSize);

    HRESULT hResult = ::CreateStreamOnHGlobal(hRes, TRUE, &pStream);

    if (hResult != S_OK)
    {
        return FALSE;
    }

    if (CMFCToolBarImages::m_bMultiThreaded)
    {
        CMFCToolBarImages::m_CriticalSection.Lock();
    }

    if (m_pImage == NULL)
    {
        m_pImage = new CImage;
        ENSURE(m_pImage != NULL);
    }

    m_pImage->Load(pStream);
    pStream->Release();

    BOOL bRes = Attach(m_pImage->Detach());

    if (CMFCToolBarImages::m_bMultiThreaded)
    {
        CMFCToolBarImages::m_CriticalSection.Unlock();
    }

    return bRes;
}

请注意,它有以下代码:

if (m_pImage == NULL)
{
    m_pImage = new CImage;
    ENSURE(m_pImage != NULL);
}

所以我们有一个CImage对象。果然:

// Attributes:
protected:
    static ATL::CImage* m_pImage;

它是CPNGImage类所使用的CMFCToolBarImages类的所有部分,而不是我自己做的事情。如果没有添加threadSafeInit-标志,那么当应用程序关闭时,调试器将始终崩溃。

0 个答案:

没有答案