抛出c ++异常:在VS2015上读取访问冲突为0xDDDDDDD

时间:2017-07-30 23:30:52

标签: c++11 sfml

我试图建立一个蛇游戏,它运行得很好,直到我玩游戏,由于某种原因我在程序结束后立即获得访问冲突,参考this-> actualState->

这里是处理actualState的cpp文件的代码:

#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();
}

我设法跟踪第63行的执行,但我似乎没有让它工作,srry我很新的c ++和sfml

这里是state.cpp文件以及详细错误(VisualStudio中有更多细节吗?): error image with state.cpp 提前谢谢你

1 个答案:

答案 0 :(得分:0)

没关系,在电脑前太多小时,没有实际的statstate =并且更改了失败状态代码。