im trying to build a snake game, and it works just fine, until i gameover, for some reason i get access violation right after the program ends, referring to this->actualState->
here is the code for the cpp file with working on actualState:
#include "Game.h"
using namespace sf;
Game::Game()
:actualStateID(END)
{
ContextSettings settings;
settings.antialiasingLevel = 8;
window.create(VideoMode(SCRN_WIDTH, SCRN_HEIGHT), "Snake", Style::Close, settings);
window.setFramerateLimit(60);
window.clear();
window.display();
if (!font.loadFromFile("data/font.ttf"))
{
//MessageBox(NULL, "Font not found! Chceck data folder!", "ERROR", NULL);
return;
}
actualStateID = MENU;
}
Game::~Game()
{
}
void Game::runGame()
{
actualState = new MenuState(MENU, window, font);
actualState->init();
while (actualStateID != END)
{
if (actualStateID != actualState->getSTATE_ID())
changeState();
handleState();
}
window.close();
}
void Game::changeState()
{
delete actualState;
switch (actualStateID)
{
case MENU:
actualState = new MenuState(MENU, window, font);
break;
case PLAY_STATE:
actualState = new PlayState(PLAY_STATE, window, font);
break;
case FAILURE:
//Image screenShot = window.capture(); //DEPRECATEDDDDDD
//Image screenShot = Texture.update(window);
//actualState = new FailureState(FAILURE, window, font, screenShot);
break;
}
actualState->init(); //error line!!
}
void Game::handleState()
{
actualStateID = actualState->handleEvents(event);
actualState->update();
actualState->render();
}
i manage to track the exeption to line 63, but i dont seem to get it to work, srry im pretty new to c++ and sfml
here goes the state.cpp file as well as the detailed error(is there any more detail in VisualStudio?): error image with state.cpp thank you in advance
Aucun commentaire:
Enregistrer un commentaire