Thread: Assertion Failed!

  1. #1
    Registered User
    Join Date
    Sep 2004
    Posts
    35

    Question Assertion Failed!

    Help!

    I have create Dialog Application with MS VC++.
    I have added a new Dialog (CHelp) resourse which contains a text box. The dialog is invoked from the main menu bar.

    I have mapped the textbox to a member variable of CHelp.
    I have added a member function to CHelp which takes a string and displays it in the text box. However, when this function is invoked i get "DEBUG Assertion Error" If I change the active configuration to release, then nothing is displayed.

    Whats wrong?

    Code:
    Code.....
    CDialog Class (Main app class)
    
    void CCadFTPDlg::OnHelp() 
    {
    	CHelp help;
    	help.loadHelpText();
    	help.DoModal();
    }
    
    //----------------------
    CHelp : public CDialog Class...
    
    
    void CHelp::loadHelpText(CString str)
    {
          m_helptext.SetWindowText(str);	
    }

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > when this function is invoked i get "DEBUG Assertion Error"
    Then read what it says very carefully. The text should at least hint as to what you're doing wrong. If its something like "hWnd!=NULL" then it means you passed a hWnd of NULL to it, and that would be wrong.

    > If I change the active configuration to release, then nothing is displayed.
    Assertions are only in debug builds, you're still passing incorrect values to the function, only you don't realise it. Whether it works now, then there is a good chance that something else will stop working later.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Sep 2004
    Posts
    35
    The only clue given by the error dialog is
    winocc.cpp

  4. #4
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    Initialize your help text inside of OnInitDialog(). This is called just after the dialog is created and just before it is displayed. All data init for objects should be done in this function.

    You are setting the text before CHelp is a valid dialog box object.
    Even though CHelp is an object, the dialog box resource is not valid until you call DoModal. At that time the dialog box object is created from the resource and then OnInitDialog() is called just prior to displaying it. This is why you need to init all your data inside of this function.

    Code:
    void CMainFrame::OnHelpText()
    {
      CDialog Help(this);
    
      CString text;
      text="Testing 123";
      Help.SetWindowText(text);
    }
    Last edited by VirtualAce; 02-14-2005 at 07:00 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. debug assertion failed
    By rahulsk1947 in forum C++ Programming
    Replies: 7
    Last Post: 06-14-2009, 03:36 PM
  2. Debug Assertion Failed!
    By IndioDoido in forum C Programming
    Replies: 31
    Last Post: 03-25-2008, 11:07 AM
  3. debug assertion failed!
    By chintugavali in forum C++ Programming
    Replies: 5
    Last Post: 12-21-2007, 04:05 AM
  4. debug assertion failed !
    By blue_gene in forum C++ Programming
    Replies: 2
    Last Post: 05-09-2004, 11:23 AM
  5. Debug Assertion Failed
    By minesweeper in forum Windows Programming
    Replies: 5
    Last Post: 12-11-2002, 05:11 PM