SFML community forums

Help => Graphics => Topic started by: C++Geek on May 08, 2015, 11:55:06 pm

Title: loadFromFile() Function Creates Exception
Post by: C++Geek on May 08, 2015, 11:55:06 pm
Hello!

I have downloaded SFML for my Visual C++ 2010 Express, and all works as expected... until I try to use the sf::Texture loadFromFile() function! Here is my code:

#include <SFML/Graphics.hpp>

int main()
{
    sf::RenderWindow window(sf::VideoMode(200, 200), "Here is a shape:");
    sf::Texture texture;

        if (!texture.loadFromFile("shape.png"))
                return -1;

        sf::Sprite sprite(texture);

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

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

    return 0;
}

This is what a message box says when I try to run the code (sfml.exe is my app's name):

Unhandled exception at 0x73231f34 in sfml.exe: 0xC0000005: Access violation reading location 0x00361000.
Title: Re: loadFromFile() Function Creates Exception
Post by: Nexus on May 12, 2015, 11:35:02 am
You probably made a mistake when configuring or linking SFML. Have you double-checked every single step in the tutorial? Please do it one more time, there are so many people missing important information.

Make sure you don't mix any compiler versions, configurations (Debug/Release) or compiler flags when compiling SFML and your own project. What SFML version do you use? Did you download an official binary or compile the library yourself?
Title: Re: loadFromFile() Function Creates Exception
Post by: C++Geek on May 12, 2015, 06:06:59 pm
I am using version 2.2. I'll try doing the linking over again and see if that works.
Title: Re: loadFromFile() Function Creates Exception
Post by: C++Geek on May 12, 2015, 06:40:14 pm
Silly mistake by me! I had my build config set to debug. I changed the .lib files to the sfml-xxx-d.lib files, and it worked! But now, when I resize the window, the sprite stretches or shrinks, depending on the window size. Is there any way to fix that?
Title: Re: loadFromFile() Function Creates Exception
Post by: zsbzsb on May 12, 2015, 06:51:21 pm
But now, when I resize the window, the sprite stretches or shrinks, depending on the window size. Is there any way to fix that?

No point in repeating what has already been said...

http://www.sfml-dev.org/tutorials/2.3/graphics-view.php#showing-more-when-the-window-is-resized
Title: Re: loadFromFile() Function Creates Exception
Post by: C++Geek on May 12, 2015, 08:35:54 pm
All right. Thanks so much!  ;D