Archived

This topic is now archived and is closed to further replies.

brass_fish

cant find bug

Recommended Posts

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:
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 189
 
here 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
    }
  
When i close the application while debugging a window pops up saying there is a segmentation fault at point 1 WinMain
  
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 --------------------

}
  
main
  
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 -------------------------------------

  
thx,brassfish extended waranty, how can I lose!

Share this post


Link to post
Share on other sites
Where in your program does it exit? Beginning, Somewhere in the app or before you exit?

Check that SetFocus thing. I don''t know but I don''t think you need that since Windows automatically sets that.

----------=Last Attacker=----------

ICQ: 120585863
E-mail: laextr@icqmail.com

Share this post


Link to post
Share on other sites
last attacker-if i am not debugging when i close the window a message pops up from Windows that says 'testCEngine.exe has encountered a problem and needs to close.' Oh, and appName is a c string. I have no idea why i put that cast there (cant remember)
yodathecoda-these are just code snippets. i dont want to post the whole thing cuz the filez are long. here are all of the files (including the dev-c++ project file) and the app:
http://brassfish.web1000.com/files.zip


[edited by - brass_fish on March 5, 2003 5:29:45 PM]

Share this post


Link to post
Share on other sites
*sigh* i remade my engine and im still getting the same error! i dont think it has anything to do w/ dx because im just creating a window. here are the new files:

  
CEngine::CEngine(HINSTANCE hInst, bool window,char* appName,ofstream* file, int w,
int h, D3DFORMAT format,DWORD styleEx,DWORD style,
WNDPROC proc):timer(file),graphics(window,w,h,format)
{
if(!proc)
proc=WndProc;
hInstance=hInst;
width=w;
height=h;
if(!window) // dont take up whole screen if not in windowed mode

{
if(w>640)
w=640;
if(h>480)
h=480;
}
WNDCLASSEX wnd;
ZeroMemory(&wnd,sizeof(wnd));
wnd.cbSize=sizeof(wnd);
wnd.hInstance=hInstance;
wnd.lpszClassName=appName;
wnd.lpfnWndProc=proc;
wnd.hbrBackground=(HBRUSH)CreateSolidBrush(RGB(0,0,0));
wnd.hIcon=LoadIcon(NULL,IDI_APPLICATION);
wnd.hIconSm=wnd.hIcon;
wnd.hCursor=wnd.hCursor;
wnd.style=0;
if(!RegisterClassEx(&wnd))
{
Log("!---RegisterClassEx FAILED in CEngine::CEngine\n");
Fatal(1,"could not create window!");
return;
}
hwnd=CreateWindowEx(styleEx,appName,appName,style,CW_USEDEFAULT,
CW_USEDEFAULT,w,h,0,0,hInstance,0);
if(!hwnd)
{
Log("!---CreateWindowEx FAILED in CEngine::CEngine\n");
Fatal(1,"could not create window!");
return;
}
ShowWindow(hwnd,SW_SHOWNORMAL);
UpdateWindow(hwnd);
}
int CEngine::run(DWORD delta,void (*update)())
{
MSG msg;
ZeroMemory(&msg,sizeof(msg));
while(msg.message!=WM_QUIT)
{
//timer.begin(); got confused w/ timer

//so im just going to comment the timer

// stuff out until i get the prob fixed

if(PeekMessage(&msg,0,0,0,PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
/*else if(timer.CheckFramerate(delta))
{
update();
timer.end();
}*/

}
return msg.wParam;
} //<-----my debugger stops the app right here

//... in main.cpp

int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE,LPSTR,int)
{
CEngine main(hInstance,1,appName);
int r=main.run(30,update);
return r; // i tried doing this:

// return main.run(30,update);

// but i got this wierd error

// having something todo w/ the

// destructor

}



extended waranty, how can I lose!

Share this post


Link to post
Share on other sites


if(!proc)
proc=WndProc


if(proc==null)//user wants to use default
proc=WndProc //set proc to default (pre-definded)

extended waranty, how can I lose!

Share this post


Link to post
Share on other sites