Original Post
hi. When I exit my test program ( a simple window using my engine ) I get a windows error that says ''testCEngine.exe has encountered a problem and needs to close.'' So i ran it through my debuger shows this:
When i close the application while debugging a window pops up saying there is a segmentation fault at point 1
WinMain
main
thx,brassfish
extended waranty, how can I lose!
function Arguments File Line -------------------------------------------------------------- ofstream::~ofstream (this=0x22feb4,__in_chrg=2) CEngine.h 57 CEngine::~CEngine (this=0x22fd98,__in_chrg=2) CEngine.h 68 WinMain () main.cpp 22 main () CEngine.cpp 189here is my code (note: the line numbers might be off because there are some #ifdef''s in there): ofstream::~ofstream and CEngine::~CEngine
CEngine(): d3d (NULL) , d3ddevice (NULL), di(NULL) , keyboard(NULL) , hwnd(NULL) , hInstance(NULL) , InitFlag(0)
{ // <-- point 1 ---------------------------------------
#ifndef NC_DEBUG
log.open(C_FILENAME);
log<<"***CEngine v1.0 starting up***\n";
#endif
}
~CEngine()
{
release();
#ifndef NC_DEBUG
log<<"***CEngine quiting...***\n";
log.close(); // <-- point 2 --------------------------
#endif
}
int WINAPI WinMain(HINSTANCE,HINSTANCE,LPSTR,int)
{
CEngine main;
main.InitWindow((char*) appName , 0 ,
WS_OVERLAPPEDWINDOW&~WS_MAXIMIZEBOX&~WS_THICKFRAME ,
0 , 600 , 400 , WndProc );
MSG msg;
while( GetMessage( &msg , NULL , 0 , 0 ) )
{
TranslateMessage( &msg );
DispatchMessage( &msg );
}
return msg.wParam; // <-- point 1 --------------------
}
bool CEngine::InitWindow( char name[] , UINT style1 , HICON hIcon ,
HICON hIconSm , char menu[] , DWORD exStyle ,
DWORD style , int width , int height , WNDPROC wndProc )
{
strcpy( appName , name );
bool bMenu=(menu==NULL)?0:1;
WNDCLASSEX wnd;
ZeroMemory( &wnd , sizeof(wnd) );
wnd.cbSize=sizeof(wnd);
wnd.hInstance=hInstance;
wnd.lpszClassName=name;
wnd.hIcon=hIcon;
wnd.hIconSm=hIconSm;
wnd.hCursor=LoadCursor( NULL , IDC_ARROW );
wnd.style=style1;
wnd.lpszMenuName=menu;
wnd.hbrBackground=(HBRUSH) GetStockObject( BLACK_BRUSH );
wnd.lpfnWndProc=wndProc;
if( !RegisterClassEx( &wnd ) )
{
FatalError( "CEngine.cpp" , 159 , "RegisterClassEx FAILED!" , 1 );
return 0;
}
RECT client={0,0,width,height};
if( !AdjustWindowRect( &client , style , bMenu ) )
{
client.left=0;
client.right=width;
client.top=0;
client.bottom=height;
Log( "!- AdjustWindowRect FAILED in function CEngine::initWindow -!\n");
}
hwnd=CreateWindowEx( exStyle , name , name , style , CW_USEDEFAULT ,
CW_USEDEFAULT , client.right-client.left ,
client.bottom-client.top , 0 , 0 , hInstance, 0 );
if( !hwnd )
{
FatalError( "CEngine.cpp" , 179 , "CreateWindowEx FAILED!" , 1 );
return 0;
}
ShowWindow( hwnd , SW_SHOWNORMAL );
UpdateWindow( hwnd );
SetFocus( hwnd );
Log( "InitWindow succeeded" );
InitFlag|=WIN_INIT;
return 1;
} // <-- point 1 -------------------------------------