SFML (32-bit VS12) - Unhandled exception at 0x701ADEF8 (msvcr110.dll) in SFML.exe: 0xC0000005: Access violation reading location 0x0526. LoadFromFile

。_饼干妹妹 提交于 2019-12-10 11:45:09

问题


The following code gives me the uncaught exception (specifically

txtr.loadFromFile("C:/Users/kidz/Documents/Visual Studio 2012/Projects/SFML/Debug/chessboard.gif");

): "Unhandled exception at 0x701ADEF8 (msvcr110.dll) in SFML.exe: 0xC0000005: Access violation reading location 0x05260000."

int _tmain(int argc, wchar_t* argv[]) {
    sf::RenderWindow window(sf::VideoMode(512, 512), "ChessPlusPlus", sf::Style::Close);
    sf::Sprite chessboard;
    sf::Texture txtr;

    txtr.loadFromFile("C:/Users/kidz/Documents/Visual Studio 2012/Projects/SFML/Debug/chessboard.gif");
    chessboard.setTexture(txtr);

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

        window.clear();
        window.draw(chessboard);
        window.display();
    }

    getwchar();
    return 0;
}

     Also, during the debugging of the program, a bunch of random ASCII characters get outputted onto the console (sometimes even personal files like essays, etc...). Then, the console goes blank (null characters) and the exception is thrown.

     Once, I was able to pause the program and scroll all the way up at it said something like: "Unable to open file 'chessboard.gif (with some random ASCII characters in the word)'" and then the long list of ASCII characters.

     Is there something wrong with SFML or am I doing something wrong? I know that SFML docs say that sometimes the file may not load and throw a exception, but in this case, it's going crazy. Also, I have randomly put a filename that does not exist and the same thing still occurred instead of throwing a file not found exception.

     I have tried the same code on Orwell Dev-C++ and it just returns a white box where the image is supposed to be and returns an exception when the file does not exist.

Some pictures:
http://i.stack.imgur.com/gq420.png
http://i.stack.imgur.com/Os8jw.png

     I will be glad to provide any extra information.

Thank you,
  Usandfriends!


回答1:


This issue arises when you're mixing debug libraries with release mode or release libraries with debug mode. Make sure to only use -d suffixed SFML libraries when in debug mode and non suffixed SFML libraries when in release mode - as stated in the official tutorial.

As a side note, it's also recommended to always use int main(). If you just want a window without the command prompt, then you can change the subsystem to window and link against sfml-main.



来源:https://stackoverflow.com/questions/20208292/sfml-32-bit-vs12-unhandled-exception-at-0x701adef8-msvcr110-dll-in-sfml-ex

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