Jump to content
  • Advertisement

Archived

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

brassfish89

can't find access violation

This topic is 5634 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I''m getting an access violation when I run my program in debug mode. But, it doesn''t show where it is. I tried putting MessageBox''s in main but none of them showed up (and yes, i did put it as the first thing in main). I have no idea where to look. so here''s the main file:
  
#include "CEngine.h"
#include "states.h"
#include "graphicengine.h"
#define appName "name"


LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);

// globals

CMain app; // handles window init


CInput input; // input


GameState* state=NULL;

// CGraphics(bool windowed,int width,int height,D3DFORMAT format)

CGraphics graphics(0,640,480,D3DFMT_X8R8G8B8); // D3D


ofstream FPS("fps.log"); // timer output file

CTimer timer(&FPS); // timer

// textures

CTexture test;

// fonts

CFont main;

int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE,LPSTR,int)
{
    app.CreateWin(hInstance,appName,640,480,WS_EX_TOPMOST,WS_POPUP,WndProc);
    SetCursor(NULL); // hide cursor

    
    graphics.setHwnd(app.hwnd);
    
    if(FAILED(graphics.InitGraphics()))
        return 0;

    input.Init(hInstance,app.hwnd);
    
    input.InitKeyboard();

    main.SetGraphicClass(&graphics);
    
    test.SetGraphicClass(&graphics);
    
    test.Create("gfx/test.png",D3DCOLOR_ARGB(255,255,0,255));
    
    GraphicEngine::InitGraphicEngine();
    
    GraphicEngine::graphicEngine->SetGraphicClass(&graphics);
    
    //GraphicEngine::graphicEngine->AddTileSet(&test,64,64,124,64,0);

    
    // initiate game class

    Game::InitGame();
    
    // initiate title class

    Title::InitTitle();

    if(FAILED(main.Create(15,"goergia")))
    {
        if(FAILED(main.Create(15)))
        {
            app.Fatal(1,"Error creating fonts!");
            return 0;
        }
    }
    
    MSG msg;
    
    state=Title::title;
    
    static bool update=1;
    
    while(1)
    {
        timer.begin();
        if(PeekMessage(&msg,0,0,0,PM_REMOVE))
        {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }
        else if(timer.CheckFramerate(5)) // keep framerate below 500

        {
            if(update)
            {
                state->update();
                update=0;
            }
            else
            {
                state->render();
                update=1;
            }
            timer.update();
            timer.end();
        }
    }
    delete GraphicEngine::graphicEngine;
    delete Game::game;
    delete Title::title;
}

LRESULT CALLBACK WndProc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam)
{
    switch(msg)
    {
        case WM_DESTROY:
            PostQuitMessage(0);
        return 0;
        case WM_SETCURSOR: // since were in fullscreen hide the cursor

            SetCursor(NULL);
        return 0;
        case WM_KEYDOWN:
            if(wParam==VK_ESCAPE) // exit on escape

            {
                SendMessage(hwnd,WM_CLOSE,0,0);
                return 0;
            }
        break;
    }
    return DefWindowProc(hwnd,msg,wParam,lParam);
}
  
and if you want you can download the whole project (dev-c++) and files here. thx brassfish
doh, nuts. Mmmm... donuts My website

Share this post


Link to post
Share on other sites
Advertisement
It's happemning for one of several reasons:

1) You are using a pointer that has not been initialised
2) You called delete for a pointer that has not been initialised

Ensure all your pointers are not NULL after being assigned.

[edited by - mathematix on April 19, 2003 7:43:11 PM]

Share this post


Link to post
Share on other sites
do you have any static objects, either in classes, or in any cpp file? those are constructed before main is called (pretty sure), its gotta be one of those.

heh man i'm retarded, i just looked at your code and noticed all those objects were in the cpp file, not the WndProc function. its crashing in one of those, i'm gonna place my bet on CGraphics, sounds like something that could easily crash try putting MessageBoxes in CGraphic's constructor

[edited by - billybob on April 19, 2003 8:11:05 PM]

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Put a breakpoint in the constructor of each class which you create a global or static instance of.

Share this post


Link to post
Share on other sites
it shouldnt be any of the classes in CEngine.h, I''ve used those in other games and they worked fine. i''ll try putting breakpoints in the singeltons.
thx brassfish



doh, nuts. Mmmm... donuts
My website

Share this post


Link to post
Share on other sites
ok, i tried putting breakpoints in the constructors but it didn''t do anything. all my static memebers are set to NULL so i don''t think its there. I''m gonna put messagebox''s in all of my CEngine classes to see if there interacting w/ a NULL pointer of mine or something.



doh, nuts. Mmmm... donuts
My website

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!