can't find access violation

Started by
7 comments, last by brassfish89 21 years ago
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
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]
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]
Put a breakpoint in the constructor of each class which you create a global or static instance of.
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
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
maybe a strcpy() or something like that, which you passed a char* to instead of a char[]?

.lick
ok, i didnt alot of commenting and i narrowed it down to CFont main. I think it has something to do w/ its name. I''ll try renaming it.


doh, nuts. Mmmm... donuts
My website
it works!!!


doh, nuts. Mmmm... donuts
My website

This topic is closed to new replies.

Advertisement