Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: loadFromFile() Function Creates Exception  (Read 3004 times)

0 Members and 1 Guest are viewing this topic.

C++Geek

  • Newbie
  • *
  • Posts: 11
    • View Profile
loadFromFile() Function Creates Exception
« 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.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: loadFromFile() Function Creates Exception
« Reply #1 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?
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

C++Geek

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: loadFromFile() Function Creates Exception
« Reply #2 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.

C++Geek

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: loadFromFile() Function Creates Exception
« Reply #3 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?

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: loadFromFile() Function Creates Exception
« Reply #4 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
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

C++Geek

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: loadFromFile() Function Creates Exception
« Reply #5 on: May 12, 2015, 08:35:54 pm »
All right. Thanks so much!  ;D

 

anything