Professional UI Solutions
Site Map   /  Register
 
 

Forum

Please Log In to post a new message or reply to an existing one. If you are not registered, please register.

NOTE: Some forums may be read-only if you are not currently subscribed to our technical support services.

Forums » Prof-UIS Tech Support » Crash when application exists Collapse All
Subject Author Date
Offer Har Jun 9, 2010 - 8:17 AM

Dear Support,


We have an application that crashes on exit.


This is the location in WindowProc of the dialog:



bool bUpdateBarsOnThisMsg = false;
    if( m_bEnabledControlBarUpdate )
    {
        CWinApp * pApp = AfxGetApp();
            ASSERT( pApp != NULL );
        BOOL bIdleMsg = pApp->IsIdleMessage(
#if _MFC_VER < 0x700
            &pApp->m_msgCur
#else
            &(::AfxGetThreadState()->m_msgCur)
#endif
            );
        if( bIdleMsg )
            bUpdateBarsOnThisMsg = true;
    }

Because the application terminates, pApp is NULL, and the rest causes the crash. Why does this happens? The message code handles in the WindowProc is 31 (WM_CANCELMODE)


Please help...


Thanks,


Ron.


This is the call-stack:


 

    ntdll.dll!7c90120e()     
	 [Frames below may be incorrect and/or missing, no symbols loaded for ntdll.dll]    
	 msvcr80d.dll!_CrtDbgBreak()  Line 89    C
	 msvcr80d.dll!_VCrtDbgReportA(int nRptType=2, const char * szFile=0x01e75e60, int nLine=370, const char * szModule=0x00000000, const char * szFormat=0x00000000, char * arglist=0x00128cac)  Line 290    C
	 msvcr80d.dll!_CrtDbgReportV(int nRptType=2, const char * szFile=0x01e75e60, int nLine=370, const char * szModule=0x00000000, const char * szFormat=0x00000000, char * arglist=0x00128cac)  Line 300 + 0x1d bytes    C
	 msvcr80d.dll!_CrtDbgReport(int nRptType=2, const char * szFile=0x01e75e60, int nLine=370, const char * szModule=0x00000000, const char * szFormat=0x00000000, ...)  Line 317 + 0x1d bytes    C
	 mfc80d.dll!AfxAssertFailedLine(const char * lpszFileName=0x01e75e60, int nLine=370)  Line 25 + 0x14 bytes    C++
	 ProfUIS287md.dll!CExtResizableDialog::WindowProc(unsigned int message=31, unsigned int wParam=0, long lParam=0)  Line 370 + 0x15 bytes    C++
	 ProfUIS287md.dll!CExtNCW<CExtResizableDialog>::WindowProc(unsigned int message=31, unsigned int wParam=0, long lParam=0)  Line 608 + 0x14 bytes    C++
	 mfc80d.dll!AfxCallWndProc(CWnd * pWnd=0x3612c534, HWND__ * hWnd=0x00142824, unsigned int nMsg=31, unsigned int wParam=0, long lParam=0)  Line 240 + 0x1c bytes    C++
	 mfc80d.dll!AfxWndProc(HWND__ * hWnd=0x00142824, unsigned int nMsg=31, unsigned int wParam=0, long lParam=0)  Line 389    C++
	 mfc80d.dll!AfxWndProcBase(HWND__ * hWnd=0x00142824, unsigned int nMsg=31, unsigned int wParam=0, long lParam=0)  Line 411 + 0x15 bytes    C++
	 user32.dll!7e418734()     
	 user32.dll!7e418816()     
	 user32.dll!7e428ea0()     
	 user32.dll!7e428eec()     
	 ntdll.dll!7c90e473()     
	 user32.dll!7e429841()     
	 user32.dll!7e42497b()     
	 user32.dll!7e43a956()     
	 msvcr80d.dll!_output_s_l(_iobuf * stream=0x00142824, const char * format=0x00189c78, localeinfo_struct * plocinfo=0x00189fa0, char * argptr=0x00012012)  Line 1166 + 0x17 bytes    C++
	 user32.dll!7e4664a2()     
	 user32.dll!7e450877()     
	 user32.dll!7e45082f()     
	 msvcr80d.dll!__crtMessageBoxA(const char * lpText=0x001295e8, const char * lpCaption=0x102d315c, unsigned int uType=73746)  Line 168 + 0x13 bytes    C
	 msvcr80d.dll!__crtMessageWindowA(int nRptType=2, const char * szFile=0x01e75e60, const char * szLine=0x0012b65c, const char * szModule=0x00000000, const char * szUserMessage=0x0012a65c)  Line 420 + 0x16 bytes    C
	 msvcr80d.dll!_VCrtDbgReportA(int nRptType=2, const char * szFile=0x01e75e60, int nLine=370, const char * szModule=0x00000000, const char * szFormat=0x00000000, char * arglist=0x0012f6f0)  Line 420 + 0x28 bytes    C
	 msvcr80d.dll!_CrtDbgReportV(int nRptType=2, const char * szFile=0x01e75e60, int nLine=370, const char * szModule=0x00000000, const char * szFormat=0x00000000, char * arglist=0x0012f6f0)  Line 300 + 0x1d bytes    C
	 msvcr80d.dll!_CrtDbgReport(int nRptType=2, const char * szFile=0x01e75e60, int nLine=370, const char * szModule=0x00000000, const char * szFormat=0x00000000, ...)  Line 317 + 0x1d bytes    C
	 mfc80d.dll!AfxAssertFailedLine(const char * lpszFileName=0x01e75e60, int nLine=370)  Line 25 + 0x14 bytes    C++
	 ProfUIS287md.dll!CExtResizableDialog::WindowProc(unsigned int message=20, unsigned int wParam=16863527, long lParam=0)  Line 370 + 0x15 bytes    C++
	 ProfUIS287md.dll!CExtNCW<CExtResizableDialog>::WindowProc(unsigned int message=20, unsigned int wParam=16863527, long lParam=0)  Line 608 + 0x14 bytes    C++
	 mfc80d.dll!AfxCallWndProc(CWnd * pWnd=0x3612c534, HWND__ * hWnd=0x00142824, unsigned int nMsg=20, unsigned int wParam=16863527, long lParam=0)  Line 240 + 0x1c bytes    C++
	 mfc80d.dll!AfxWndProc(HWND__ * hWnd=0x00142824, unsigned int nMsg=20, unsigned int wParam=16863527, long lParam=0)  Line 389    C++
	 mfc80d.dll!AfxWndProcBase(HWND__ * hWnd=0x00142824, unsigned int nMsg=20, unsigned int wParam=16863527, long lParam=0)  Line 411 + 0x15 bytes    C++
	 user32.dll!7e418734()     
	 user32.dll!7e418816()     
	 user32.dll!7e428ea0()     
	 user32.dll!7e428eec()     
	 ntdll.dll!7c90e473()     
	 user32.dll!7e42b1a8()     
	 mfc80d.dll!CWnd::DestroyWindow()  Line 993 + 0xd bytes    C++
>    mfc80d.dll!CStatic::~CStatic()  Line 33    C++
	 ProfUIS287md.dll!CExtLabel::~CExtLabel()  Line 77 + 0x7a bytes    C++
	 UIEventLog.dll!CEventLogPopupDlg::~CEventLogPopupDlg()  Line 30 + 0x11 bytes    C++

Technical Support Jun 11, 2010 - 8:19 AM

The CWnd::DestroyWindow() method is virtual and it can be overridden. But this is not important. The really important thing is that the CWnd::DestroyWindow() method invokes the ::DestroyWindow() Win32 API which causes the WM_DESTROY message be sent to the window procedure. The WM_DESTROY message is passed through the WindowProc() virtual method and the OnDestroy() handler method. Then the WM_NCDESTROY message is delivered to the window procedure. This is specific message. It’s not passed through the WindowProc() virtual method. MFC uses the PostNcDestroy() virtual method for notifying about the WM_NCDESTROY message. Both WM_DESTROY and WM_NCDESTROY messages are sent to each window only once.

Please take a look at the bottom of the call stack. It looks like some label window destroys itself in the destructor. This is not in style of MFC. Window handles should be destroyed before the C++ objects become deleted. The C++ objects must not destroy subclassed window handles in the destructor code.

Technical Support Jun 10, 2010 - 10:26 AM

The AfxGetApp() API must never return NULL if you have no memory damages, if a regular DLL manages MFC state switching correctly and if your code destroys all the windows before exiting process. Please provide us with more information about type of your project and about when this situation occur? Please also set the AfxGetApp() as next statement in debugger and try to debug what’s happened inside and why such bad return value is generated.

Offer Har Jun 10, 2010 - 10:33 AM

Hi,
This is simple MDI application, nothing special about it.
The thing is that I know that this is called when the application is on its way out.
What I don’t understand why the destructor of the dialog, calls DestroyWindow - the destructor was called after the main window was already destroyed, and now the application is just freeing its memory.
Shouldn’t the DestroyWindow be called from OnDestroy of the dialog?
I cannot run the application now, as I’m not in the office, but as I recall the rest of the stack was at the very end of the process, and no other windowing functions were in the stack, only freeing of memory.
Thanks,
Ron.

Offer Har Jun 10, 2010 - 10:39 AM

OK... the DestroyWindow is MFC code... not yours.

However, a few lines up the stack, your function start to appear -


     ProfUIS287md.dll!CExtResizableDialog::WindowProc(unsigned int message=20, unsigned int wParam=16863527, long lParam=0) Line 370 + 0x15 bytes C++
     ProfUIS287md.dll!CExtNCW<CExtResizableDialog>::WindowProc(unsigned int message=20, unsigned int wParam=16863527, long lParam=0) Line 608 + 0x14 bytes C++

This I don’t understand - how come that from the DestroyWindow the CExtResizableDialog’ WindowProc is called.
Any ideas?