Click here to Skip to main content
15,867,977 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear All,
I am working on a project which is a mixture of dialog and MDI. The project started as a tabbed dialog project. Later MDI was added to it. On clicking one of the tabs the MDI is invoked. Without clicking the a particular tab it remains only a dialog based project.
The project works fine in release build. When I do a debug build I get a crash when I click on the tab that initializes the MDI main frame and window. Given below is the piece of code that is executed for MID window creation.
The crash message is
Unhandled exception at 0x590C0983 (msvcr120d.dll) in MarkBullV3.exe: 0xC000041D: An unhandled exception was encountered during a user callback.

Any help would be very much appreciated. Feel free to ask any question you may have.

Thanks & Regards,
Rakesh


pDocTemplate = new CMultiDocTemplate(IDR_Test1TYPE,
RUNTIME_CLASS(CTest1Doc),
RUNTIME_CLASS(CChildFrame), //custom MDI child frame
RUNTIME_CLASS(CTest1View));
if (!pDocTemplate)
return FALSE;
AddDocTemplate(pDocTemplate);

LOGD.LOGRP(FL, "After pDocTemplate creation");

pMainFrame = new CMainFrame;
if (!pMainFrame || !pMainFrame->LoadFrame(IDR_MAINFRAME1))
{
LOGD.LOGRP(FL, "main Frame not created");
delete pMainFrame;
return FALSE;
}

m_pMainWnd = pMainFrame;

for (i = 0; i < 16; i++)
theApp.OnFileNew();


LOGD.LOGRP(FL, "Check0");

//pMainFrame->MDITile();

CCommandLineInfo cmdInfo;
ParseCommandLine(cmdInfo);
pMainFrame->ShowWindow(m_nCmdShow);
LOGD.LOGRP(FL, "Before UpdateWindow");
pMainFrame->UpdateWindow();
LOGD.LOGRP(FL, "After UpdateWindow");
totCustomPlotCount = 0;
LOGD.LOGRP(FL, "End of window creation in initinstance11");

I find the crash happens on UpdateWindow. So I commented that and I find that the crash still happens.

Given below is the stack on crash

msvcr120d.dll!_CrtDbgBreak() Line 87 C

msvcr120d.dll!_VCrtDbgReportA(int nRptType, void * returnAddress, const char * szFile, int nLine, const char * szModule, const char * szFormat, char * arglist) Line 290 C

msvcr120d.dll!_CrtDbgReportV(int nRptType, void * returnAddress, const char * szFile, int nLine, const char * szModule, const char * szFormat, char * arglist) Line 262 C
msvcr120d.dll!_CrtDbgReport(int nRptType, const char * szFile, int nLine, const char * szModule, const char * szFormat, ...) Line 279 C
> mfc120d.dll!AfxAssertFailedLine(const char * lpszFileName, int nLine) Line 24 C++
mfc120d.dll!CScrollView::OnPrepareDC(CDC * pDC, CPrintInfo * pInfo) Line 387 C++
mfc120d.dll!CView::OnPaint() Line 185 C++

mfc120d.dll!CWnd::OnWndMsg(unsigned int message, unsigned int wParam, long lParam, long * pResult) Line 2448 C++

mfc120d.dll!CWnd::WindowProc(unsigned int message, unsigned int wParam, long lParam) Line 2094 C++

mfc120d.dll!AfxCallWndProc(CWnd * pWnd, HWND__ * hWnd, unsigned int nMsg, unsigned int wParam, long lParam) Line 282 C++

mfc120d.dll!AfxWndProc(HWND__ * hWnd, unsigned int nMsg, unsigned int wParam, long lParam) Line 435 C++

mfc120d.dll!AfxWndProcBase(HWND__ * hWnd, unsigned int nMsg, unsigned int wParam, long lParam) Line 299 C++

user32.dll!744084f3() Unknown
[Frames below may be incorrect and/or missing, no symbols loaded for user32.dll]
[External Code]
V3.exe!V10App::InitInstance() Line 291 C++
[External Code]
V3.exe!WinMain(HINSTANCE__ * hInstance, HINSTANCE__ * hPrevInstance, char * lpCmdLine, int nCmdShow) Line 26 C++
[External Code]


The last function called is below

C#
_CRTIMP int __cdecl _VCrtDbgReportA
(
    int nRptType,
    void * returnAddress,
    const char * szFile,
    int nLine,
    const char * szModule,
    const char * szFormat,
    va_list arglist
    )
{
    int retval=0;
    int handled=FALSE;
    char szLineMessage[DBGRPT_MAX_MSG] = {0};
    char szOutMessage[DBGRPT_MAX_MSG] = {0};
    wchar_t szOutMessage2[DBGRPT_MAX_MSG] = {0};
    char szUserMessage[DBGRPT_MAX_MSG] = {0};

    if (nRptType < 0 || nRptType >= _CRT_ERRCNT)
        return -1;

    /*
     * handle the (hopefully rare) case of
     *
     * 1) ASSERT while already dealing with an ASSERT
     *      or
     * 2) two threads asserting at the same time
     */

    __try
    {

        if (_CRT_ASSERT == nRptType && InterlockedIncrement(&_crtAssertBusy) > 0)
        {
            /* use only 'safe' functions -- must not assert in here! */

            _ERRCHECK(_itoa_s(nLine, szLineMessage, DBGRPT_MAX_MSG, 10));

            OutputDebugStringA("Second Chance Assertion Failed: File ");
            OutputDebugStringA(szFile ? szFile : "<file unknown>");
            OutputDebugStringA(", Line ");
            OutputDebugStringA(szLineMessage);
            OutputDebugStringA("\n");

            _CrtDbgBreak();
            retval=-1;
        }
        else
        {

            // Leave space for ASSERTINTRO1 and "\r\n"
            if (szFormat)
            {
                int szlen = 0;
                _ERRCHECK_SPRINTF(szlen = _vsnprintf_s(szUserMessage, DBGRPT_MAX_MSG,
                                                       DBGRPT_MAX_MSG - 2- max(sizeof(ASSERTINTRO1),sizeof(ASSERTINTRO2)),
                                                       szFormat, arglist));
                if (szlen < 0)
                {
                    _ERRCHECK(strcpy_s(szUserMessage, DBGRPT_MAX_MSG, DBGRPT_TOOLONGMSG));
                }
            }

            if (_CRT_ASSERT == nRptType)
                _ERRCHECK(strcpy_s(szLineMessage, DBGRPT_MAX_MSG, szFormat ? ASSERTINTRO1 : ASSERTINTRO2));

            _ERRCHECK(strcat_s(szLineMessage, DBGRPT_MAX_MSG, szUserMessage));

            if (_CRT_ASSERT == nRptType)
            {
                if (_CrtDbgMode[nRptType] & _CRTDBG_MODE_FILE)
                    _ERRCHECK(strcat_s(szLineMessage, DBGRPT_MAX_MSG, "\r"));
                _ERRCHECK(strcat_s(szLineMessage, DBGRPT_MAX_MSG, "\n"));
            }

            if (szFile)
            {
                int szlen = 0;
                _ERRCHECK_SPRINTF(szlen = _snprintf_s(szOutMessage, DBGRPT_MAX_MSG, DBGRPT_MAX_MSG - 1, "%s(%d) : %s",
                                                      szFile, nLine, szLineMessage));
                if (szlen < 0)
                {
                    _ERRCHECK(strcpy_s(szOutMessage, DBGRPT_MAX_MSG, DBGRPT_TOOLONGMSG));
                }
            }
            else
                _ERRCHECK(strcpy_s(szOutMessage, DBGRPT_MAX_MSG, szLineMessage));

            {
                size_t ret = 0;
                errno_t e = 0;
                _ERRCHECK_EINVAL_ERANGE(e = mbstowcs_s(&ret, szOutMessage2, DBGRPT_MAX_MSG, szOutMessage, _TRUNCATE));
                if(e != 0)
                    _ERRCHECK(wcscpy_s(szOutMessage2, DBGRPT_MAX_MSG, _CRT_WIDE(DBGRPT_INVALIDMSG)));

            }

            /* User hook may handle report.
               We have to check the ANSI Hook2 List & then the UNICODE Hook2 List.
               Then we have check any ANSI individual Hook set through
               SetReportHook */

            if (_pReportHookList || _pReportHookListW)
            {
                ReportHookNode *pnode=NULL;
                ReportHookNodeW *pnodeW=NULL;

                _mlock(_DEBUG_LOCK);
                __try
                {
                    for (pnode = _pReportHookList; pnode; pnode = pnode->next)
                    {
                        int hook_retval=0;
                        if ((*pnode->pfnHookFunc)(nRptType, szOutMessage, &hook_retval))
                        {
                            handled=TRUE;
                            retval=hook_retval;
                            break;
                        }
                    }

                    if(!handled)
                    {
                        for (pnodeW = _pReportHookListW; pnodeW; pnodeW = pnodeW->next)
                        {
                            int hook_retval=0;
                            if ((*pnodeW->pfnHookFunc)(nRptType, szOutMessage2, &hook_retval))
                            {
                                handled=TRUE;
                                retval=hook_retval;
                                break;
                            }
                        }
                    }
                }
                __finally
                {
                    _munlock(_DEBUG_LOCK);
                }
            }
            if(!handled)
            {
                if(_pfnReportHook)
                {
                    int hook_retval=0;
                    if(((*_pfnReportHook)(nRptType, szOutMessage, &hook_retval)))
                    {
                        handled=TRUE;
                        retval=hook_retval;
                    }
                }

                if (!handled)
                {
                    if (_CrtDbgMode[nRptType] & _CRTDBG_MODE_FILE)
                    {
                        if (_CrtDbgFile[nRptType] != _CRTDBG_INVALID_HFILE)
                        {
                            DWORD written;
                            WriteFile(_CrtDbgFile[nRptType], szOutMessage, (unsigned long)strlen(szOutMessage), &written, NULL);
                        }
                    }

                    if (_CrtDbgMode[nRptType] & _CRTDBG_MODE_DEBUG)
                    {
                        OutputDebugStringA(szOutMessage);
                    }

                    if (_CrtDbgMode[nRptType] & _CRTDBG_MODE_WNDW)
                    {
                        szLineMessage[0] = 0;
                        if (nLine)
                        {
                            _ERRCHECK(_itoa_s(nLine, szLineMessage, DBGRPT_MAX_MSG, 10));
                        }
                        retval = __crtMessageWindowA(nRptType, returnAddress, szFile, (nLine ? szLineMessage : NULL), szModule, szUserMessage);
                    }
                }
            }
        }
    }
    __finally
    {
        if (_CRT_ASSERT == nRptType)
        {
            InterlockedDecrement(&_crtAssertBusy);
        }
    }

    return retval;
}



C#
>	mfc120d.dll!CScrollView::OnPrepareDC(CDC * pDC, CPrintInfo * pInfo) Line 387	C++




C#
void CScrollView::OnPrepareDC(CDC* pDC, CPrintInfo* pInfo)
{
	ASSERT_VALID(pDC);

	if (m_bInitialRedraw)
	{
		return;
	}

#ifdef _DEBUG
	if (m_nMapMode == MM_NONE)
	{
		TRACE(traceAppMsg, 0, "Error: must call SetScrollSizes() or SetScaleToFitSize()");
		TRACE(traceAppMsg, 0, "\tbefore painting scroll view.\n");
		ASSERT(FALSE);////Assertion called from here
		return;
	}
#endif //_DEBUG
	ASSERT(m_totalDev.cx >= 0 && m_totalDev.cy >= 0);
	switch (m_nMapMode)
	{
	case MM_SCALETOFIT:
		pDC->SetMapMode(MM_ANISOTROPIC);
		pDC->SetWindowExt(m_totalLog);  // window is in logical coordinates
		pDC->SetViewportExt(m_totalDev);
		if (m_totalDev.cx == 0 || m_totalDev.cy == 0)
			TRACE(traceAppMsg, 0, "Warning: CScrollView scaled to nothing.\n");
		break;

	default:
		ASSERT(m_nMapMode > 0);
		pDC->SetMapMode(m_nMapMode);
		break;
	}

	CPoint ptVpOrg(0, 0);       // assume no shift for printing
	if (!pDC->IsPrinting())
	{
		ASSERT(pDC->GetWindowOrg() == CPoint(0,0));

		// by default shift viewport origin in negative direction of scroll
		ptVpOrg = -GetDeviceScrollPosition();

		if (m_bCenter)
		{
			CRect rect;
			GetClientRect(&rect);

			// if client area is larger than total device size,
			// override scroll positions to place origin such that
			// output is centered in the window
			if (m_totalDev.cx < rect.Width())
				ptVpOrg.x = (rect.Width() - m_totalDev.cx) / 2;
			if (m_totalDev.cy < rect.Height())
				ptVpOrg.y = (rect.Height() - m_totalDev.cy) / 2;
		}
	}
	pDC->SetViewportOrg(ptVpOrg);

	CView::OnPrepareDC(pDC, pInfo);     // For default Printing behavior
}



/////////////////////////////////////////////////////////////////////////

OnPaint function and the runtime parameters are

void CView::OnPaint()
{
// standard paint routine
CPaintDC dc(this);
OnPrepareDC(&dc);
OnDraw(&dc);
}


- dc {hWnd=0x002003d4 {unused=??? }} CPaintDC
- CDC {hDC=0x30011223 {unused=??? } attrib=0x30011223 {unused=??? }} CDC
+ CObject {...} CObject
+ m_hDC 0x30011223 {unused=??? } HDC__ *
+ m_hAttribDC 0x30011223 {unused=??? } HDC__ *
m_bPrinting 0 int
+ m_hWnd 0x002003d4 {unused=??? } HWND__ *
- m_ps {hdc=0x30011223 {unused=??? } fErase=0 rcPaint={top=0 bottom=247 left=0 right=424} ...} tagPAINTSTRUCT
+ hdc 0x30011223 {unused=??? } HDC__ *
fErase 0 int
+ rcPaint {top=0 bottom=247 left=0 right=424} tagRECT
fRestore 0 int
fIncUpdate 0 int
+ rgbReserved 0x0017851c "" unsigned char[32]
- this 0x0b19a708 {hWnd=0x002003d4 {unused=??? }} CView *
- [CTest1View] {hWnd=0x002003d4 {unused=??? }} MarkBullV3.exe!CTest1View
+ CScrollView {hWnd=0x002003d4 {unused=??? }} MarkBullV3.exe!CScrollView
Is_Graph_Data_3D 0 int
Graph_Type 4 int
WinIndentifier 4 int
WinIdentifierCnst -842150451 int
+ pData2 0x0b19a7c4 {{x=-431602080. y=-431602080. z=-431602080. }, {x=-431602080. y=-431602080. z=-431602080. }, ...} MarkBullV3.exe!t_FLOATPOINT[2000]
+ pData3 0x0b1a0584 {{x=-431602080. y=-431602080. z=-431602080. }, {x=-431602080. y=-431602080. z=-431602080. }, ...} MarkBullV3.exe!t_FLOATPOINT[2000]
+ pData1 0x0b1a6344 {{x=-431602080. y=-431602080. z=-431602080. }, {x=-431602080. y=-431602080. z=-431602080. }, ...} MarkBullV3.exe!t_FLOATPOINT[2000]
ColR 0 unsigned long
ColG 0 unsigned long
ColB 0 unsigned long
FirstEntry 0 int
+ m_LinePlot {hWnd=0x00000000 <null>} MarkBullV3.exe!CLinePlot
+ m_cmbStyle {hWnd=0x00000000 <null>} MarkBullV3.exe!CComboBox
+ m_lstReceived {hWnd=0x00000000 <null>} MarkBullV3.exe!CListBox
cnumValuesPkOrderSqncBkSwing -842150451 int
+ PkAngPosSqncBkSwing 0x0b1acc24 {-842150451, -842150451, -842150451, -842150451, -842150451, -842150451, -842150451, -842150451, ...} int[10]
+ PkOrderSqncBkSwing 0x0b1acc4c {-842150451, -842150451, -842150451, -842150451, -842150451, -842150451, -842150451, -842150451, ...} int[10]
OnLButtonDownId 0 unsigned int
rotUp 0 int
rotDown 0 int
rotLeft 0 int
rotRight 0 int
zoomHdClub 0 int
unzoomHdClub 0 int
genTestVariable 0 int
+ CWnd {hWnd=0x002003d4 {unused=??? }} CWnd
+ m_pDocument 0x081dfc10 {...} CDocument *
m_bInitialRedraw 0 int

What I have tried:

I have tried to comment UpdateWindow. I have tried to see the stack and find possible pointers that may have gone wrong, but not much clarity came out of it.
Regards,
Rakesh
Posted
Comments
Richard MacCutchan 17-Feb-16 6:50am    
You cannot seriously expect anyone to go through all that code. Use your debugger to find out where the crash happens and gather some proper details. Then remove all the code from your question that is not relevant to the problem.
Member 11380615 17-Feb-16 7:20am    
Thanks Richard for your thought. I did debug it but am still looking for some hint. The problem text is right in the top and I have tried to provide relevant stack details and pieces of function executed by the stack. I will try to optimize it further to make it more readable.
Regards,
Rakesh

1 solution

It seems you already found the asserting line and it tells you what has happened (the messages should have been also printed to the Debug Output window):
# ifdef _DEBUG
	if (m_nMapMode == MM_NONE)
	{
		TRACE(traceAppMsg, 0, "Error: must call SetScrollSizes() or SetScaleToFitSize()");
		TRACE(traceAppMsg, 0, "\tbefore painting scroll view.\n");
		ASSERT(FALSE);////Assertion called from here
		return;
	}
# endif //_DEBUG

To resolve the error ensure that the requirements are met when creating your CScrollView derived views (probably called by OnFileNew()).
 
Share this answer
 
v2
Comments
Member 11380615 17-Feb-16 7:17am    
Thanks Jochen for your thoughts. I dont know how to address this since this isworking fine release mode. Could you throw some more light on what I should do.
Regards,
Rakesh
Jochen Arndt 17-Feb-16 7:24am    
It might not work as expected in release mode. The assertion is there to inform you that an important setup has not yet been performed.

You should now check the creation of your CSrollView derived class. Read first the documentation for CScrollView, the mentioned functions, and the map mode.

Optionally search for the error message. One result will be:
https://social.msdn.microsoft.com/Forums/en-US/29fab6a4-8c60-4966-8366-58f81bf0ff9b/scrolling-the-view-problem?forum=vcmfcatl
nv3 17-Feb-16 8:48am    
Yes, that seems to be the problem. Good shot, Jochen.
Member 11380615 19-Feb-16 0:11am    
The problem was the ScrollSizes were not set. My view class was derived from CSrollView.
I tried setting the scrollsizes in UpdateInit and it worked fine.
Thanks Jochen, you are very good. The swiftness with which you found the problem is inspiring.
Jochen Arndt 19-Feb-16 2:43am    
Fine to hear that it is solved and thank you for your feedback.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900