Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SFML error loadFromFile()

I have the following code:

#include <SFML\Graphics.hpp>
#include <iostream>

int main(int argc, char* argv[])
{
    sf::RenderWindow window(sf::VideoMode(640, 480), "SFML Render");
    sf::Image image;
    sf::Texture texture;
    sf::Sprite sprite;

    image.loadFromFile("D:/Project/Sprites/bt1.png");
    texture.loadFromImage(image);
    sprite.setTexture(texture);
    sprite.setPosition(100.0f, 100.0f);

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

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

    return 0;
}

It's very simple, but it didn't work.

I tried using different kinds of paths:

D:/Project/CPP/Game_Engine/Debug/sprites/first.bmp
D:\\Project\\CPP\\Game_Engine\\Debug\\sprites\\first.bmp
d:\\Project\\CPP\\Game_Engine\\Debug\\sprites\\first.bmp

Then I tried using different files:

D:/Project/Sprites/bt.png
D:/Project/Sprites/anim.bmp
D:/Project/Sprites/boy.jpg

Compiler indicates at the following line:

image.loadFromFile("D:/Project/Sprites/bt1.png");

More precisely, Program crashes on this line. enter image description here

My configuration is the following: enter image description here

Error/crash message is the following:

Необработанное исключение по адресу 0x5007DEF8 (msvcr110.dll) в SFML_ERROR.exe: 0xC0000005: нарушение прав доступа при чтении по адресу 0x03BC1000.

Translation is the following:

Unhandled exception at 0x5007DEF8 (msvcr110.dll) in SFML_ERROR.exe: 0xC0000005: Access violation reading on Address 0x03BC1000.

like image 215
Ivan Avatar asked Jan 15 '14 07:01

Ivan


1 Answers

My problem is mixed Debug/Release, I used sfml-window.lib, but I have to use `sfml-window-d.lib'. I can't use the debug SFML library because I am using VC++ 2013 (v120, but SFML requires v110). So, I recompiled the official library and it worked!

like image 155
Ivan Avatar answered Nov 17 '22 08:11

Ivan