Debug Assertion Failure! ?
When I try and execute my MFC code,
I get a Debug Assertion Failure and
then it says that the code has peformed an error and wil be closed down.
What does this mean? and how can I get rid of it?
[213 byte] By [
GetFahad] at [2007-11-17 22:39:28]

# 1 Re: Debug Assertion Failure! ?
what type of app is and what is exactly the message error and where is produced?
# 2 Re: Debug Assertion Failure! ?
Tell what the assertion is, the file name, and the line number
Brandon Parker
# 3 Re: Debug Assertion Failure! ?
when the assertion occurs , it will ask something like press "retry" to debug.
then press retry :D
you'll see something like ASSERT or one of it's derivatives
ASSERT(::IsWindow(m_hWnd)) or so
somewhere (deep) inside mfc's own code.
Now you can take a look at your callstack.
If you don't find it in the debug mode, you can show it by using
the menu: View|debug windows|call stack
Here you'll see the call stack, and you'll see where it went wrong.
If you look through the callstack you can see the function that you wrote that is (directly) responsible for the assertion failure.
click on the function and you'll see your function call
Hope this helps
Steven Roelants
# 4 Re: Debug Assertion Failure! ?
Its a win32 application
The error goes like:
Debug Assertion failed
Program c:\....\mfc2.exe
File: winOcc.cpp
Line 301
For more information......
abort - retry- ignore
When I choose retry or ignore. it gives me another message saying its caused an error and has to be closed down.
Thnx!
# 5 Re: Debug Assertion Failure! ?
k, do you have any idea where it happens?
Maybe you can set a breakpoint (debug mode) just in front of the call that gives the assertion and then step into it, to look where it goes wrong
# 6 Re: Debug Assertion Failure! ?
:( thnx 4 ur reply
I have an idea where its going wrong but not sure what to do with it:
//mfc2.cpp
#include <afxwin.h>
#include "mfc2.h"
#include "resource.h"
char str[80];
CMainWin::CMainWin()
{
Create(NULL,"BLABLA",WS_OVERLAPPEDWINDOW,rectDefault,NULL,"Mfc3",0,NULL);
// Create(NULL,"bla bla");
// hPen.CreatePen(PS_SOLID,6,RGB(0,0,255));
// r.top = 100;
// r.left = 100;
// r.bottom = 400;
// r.right = 400;
}
BOOL CApp::InitInstance()
{
m_pMainWnd = new CMainWin;
m_pMainWnd->ShowWindow(m_nCmdShow);
m_pMainWnd->UpdateWindow();
return TRUE;
}
BEGIN_MESSAGE_MAP(CMainWin,CFrameWnd)
ON_COMMAND(IDM_GREETINGS, OnGreetings)
END_MESSAGE_MAP()
afx_msg void CMainWin::OnGreetings()
{
//wil add more here later;
}
CApp App;
I have also attached my .cpp
# 7 Re: Debug Assertion Failure! ?
This is an extract of winocc.cpp at 301
BOOL CWnd::ShowWindow(int nCmdShow)
{
ASSERT(::IsWindow(m_hWnd));
if (m_pCtrlSite == NULL)
return ::ShowWindow(m_hWnd, nCmdShow);
else
return m_pCtrlSite->ShowWindow(nCmdShow);
}
The problem is in the ASSERT statement.
The CWnd object is not a valid window.
# 8 Re: Debug Assertion Failure! ?
If the problem is in the ASSERT Statement
then
Can I do something about this? :confused:
How would you modift the code to make it work? :(
I am a newbie at MFC so REALLY DO appreciate your help with this
# 9 Re: Debug Assertion Failure! ?
Im sorry but I dont mean to be rude at all. But, that file you attached is sick. You just need to trash it and start over. Then do a little reading, download some sample MFC projects and fool around with them for awhile.
Brandon
# 10 Re: Debug Assertion Failure! ?
What kind of window is your CMainWin derived from? Are you calling its base constructor anywhere? You don't seem to be.
John E at 2007-11-10 8:50:48 >
