Wrox Programmer Forums
|
BOOK: Ivor Horton's Beginning Visual C++ 2010
This is the forum to discuss the Wrox book Ivor Horton's Beginning Visual C++ 2010 by Ivor Horton; ISBN: 9780470500880
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Ivor Horton's Beginning Visual C++ 2010 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 12th, 2012, 06:16 PM
Registered User
 
Join Date: Feb 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Question Sketcher MFC Debug Assertion failure

I have working through the Sketcher MFC MDI app in Chapt. 15, and all was going swimmingly until I added toolbar buttons for the functions (pp 924ff). On run, I then get a" Debug Assertion failed!" Following the reference in the popup message, the error was triggered from a function in afxtoolbar.cpp, which I paste here:
Code:
 BOOL __stdcall CMFCToolBar::SetUserImages(CMFCToolBarImages* pUserImages)
{
    ENSURE(pUserImages != NULL);
    if (!pUserImages->IsValid())
    {
        ASSERT(FALSE);
        return FALSE;
    }

    if (m_sizeImage != pUserImages->GetImageSize())
    {
        ASSERT(FALSE);
        return FALSE;
    }

    m_pUserImages = pUserImages;
    return TRUE;
}
My message comes from the second test, on GetImageSize(), so evidently the problem has to do with the size of the toolbar icons.


On doing some debugging, I find that the assertion failure come right after the following code in Mainframe.cpp (in CMainFrame::OnCreate) :
Code:
 if (CMFCToolBar::GetUserImages() == NULL)
    {
        // load user-defined toolbar images
        if (m_UserImages.Load(_T(".\\UserImages.bmp")))
        {
            CMFCToolBar::SetUserImages(&m_UserImages);
        }
    }
It turns out CMFCToolBar::GetUserImages() is returning NULL, and loading UserImages.bmp, rather then the icons stored in the app's .rc file. UserImages.bmp contains tiny MS icons (a little man, house, question mark, red X mark etc), NOT the icons I have created in the resource editor. The problem seems to boil down to figuring out why GetUserImages is returning NULL here.


I don't know if it's relevant, but at the top of the call stack (just above the breakpoint in CMainFrame::OnCreate) is:
mfc100ud.dll!5e2b292f()
[Frames below may be incorrect and/or missing, no symbols loaded for mfc100ud.dll]


With some help from the MSDN forum, I found I could get rid of the assert failure by simply removing the code, OR adding a line:


Code:
  if (CMFCToolBar::GetUserImages() == NULL)
    {
        // load user-defined toolbar images
        if (m_UserImages.Load(_T(".\\UserImages.bmp")))
        {
            m_UserImages.SetImageSize(CSize(16, 16), FALSE);  //new line
            CMFCToolBar::SetUserImages(&m_UserImages);
        }
    }
While both of these worked, I don't really understand why: what GetUserImages() is doing and why it returns NULL here, and looks for the UserImages.bmp file rather than recognising that the toolbar button icons are in the .rc file.


I'd be grateful for clarification and guidance on this!





Similar Threads
Thread Thread Starter Forum Replies Last Post
about sketcher examble ch 17 MFC eng/elsayed BOOK: Ivor Horton's Beginning Visual C++ 2010 2 March 20th, 2012 07:41 PM
Debug assertion failure for wincore aparnakamath2000 Visual C++ 0 August 28th, 2007 05:49 AM
Debug assertion about m_pCtrlSite attaboyu Visual C++ 10 November 14th, 2005 01:53 PM
"Debug Assertion Failure" elleetan Visual C++ 3 September 20th, 2005 06:25 AM
Help in Assertion failure abdelkader Visual C++ 0 December 30th, 2003 10:43 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.