6

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.

FacelessTiger
  • 89
  • 1
  • 1
  • 11
Ivan
  • 992
  • 1
  • 10
  • 22
  • 2
    Could you please post the text (selectable, that is) of the error/crash message? – Mark Garcia Jan 15 '14 at 07:29
  • 1
    "The loadFromFile function sometimes fails with no obvious reason. First, check the error message printed by SFML in the standard output (check the console)." - What message is being printed? – Floris Velleman Jan 15 '14 at 07:29
  • I cant use `sf::err`, program crashes exactly on loadFromFile(), therefore next line don't executed. Error/crash message is above. – Ivan Jan 15 '14 at 07:42

1 Answers1

17

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!

FacelessTiger
  • 89
  • 1
  • 1
  • 11
Ivan
  • 992
  • 1
  • 10
  • 22
  • You should mark your response as answer - although technically speaking it was my answer on the forum, haha. :D – Lukas Jan 15 '14 at 15:41
  • I have the same problem with fonts. I am using VS 2010 - in release mode I think? (How do I check that?) I am using the libs WITHOUT the -d option? Everything compiles and links but the loadFromFile function causes the same error - how can I fix this? – FreelanceConsultant Aug 19 '15 at 19:24
  • For anyone else who faces this problem, make sure that you have included sml-.lib/.dll instead of sml--d.lib/.dll for release mode and vice versa for debug mode, I wasted good one hour on this – Karan Joisher Dec 17 '16 at 14:26