Opening SFML window gives memory read error

浪尽此生 提交于 2019-12-04 06:22:36

问题


I'm trying to open a SFML window, but every time it is launched it says "Access violation reading location: 0xCCCCCCC0." The error is occuring in the init() method. Relevant code:

class AirportGame {
private:
    sf::RenderWindow window;
public:
    void init();
    int run();

/

void AirportGame::init() {
    window.create(sf::VideoMode(800, 600), "SFML window");
}

int AirportGame::run() {
    init();

    while (window.isOpen()) {
        sf::Event event;

        while (window.pollEvent(event)) {
            if (event.type == sf::Event::Closed) {
                window.close();
            }
        }
    }

    return 0;
}

int main() {
    AirportGame* app = new AirportGame();
    return app->run();
}

It happens sometime after init, because the actual window is open. There is no mention in the debugger of 0xCCCCCC0.


回答1:


Fixed it!

Turns out under the C++ pre-processor I set the definition to SFML_STATIC instead of SFML_DYNAMIC




回答2:


Set window to a RenderWindow *window;

and create it with

window = new sf::RenderWindow( /*your stuff or default initialize*/ );

and then call

window->create( /*your settings*/ );

if you didn't already initialize it.

From then on just access window using '->' instead of '.'



来源:https://stackoverflow.com/questions/20966064/opening-sfml-window-gives-memory-read-error

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!