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

Author Topic: Unhandled exceptions thrown from sprite tutorial  (Read 2810 times)

0 Members and 1 Guest are viewing this topic.

Chadwell

  • Newbie
  • *
  • Posts: 5
    • View Profile
Unhandled exceptions thrown from sprite tutorial
« on: March 23, 2009, 07:10:07 am »
Hey, I'm having some issues with the code from the Image and Sprite tutorial. Basically here is my code:

Code: [Select]

////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Graphics.hpp>


////////////////////////////////////////////////////////////
/// Entry point of application
///
/// \return Application exit code
///
////////////////////////////////////////////////////////////
int main()
{
    // Create the main rendering window
    sf::RenderWindow App(sf::VideoMode(800, 600, 32), "SFML Graphics");

    // Load the sprite image from a file
    sf::Image Image;
    if (!Image.LoadFromFile("sprite.bmp"))
        return EXIT_FAILURE;

    // Create the sprite
    sf::Sprite Sprite(Image);

    // Change its properties
    Sprite.SetColor(sf::Color(0, 255, 255, 128));
    Sprite.SetPosition(200.f, 100.f);
    Sprite.SetScale(2.f, 2.f);

    // Start game loop
    while (App.IsOpened())
    {
        // Process events
        sf::Event Event;
        while (App.GetEvent(Event))
        {
            // Close window : exit
            if (Event.Type == sf::Event::Closed)
                App.Close();
        }

        // Get elapsed time
        float ElapsedTime = App.GetFrameTime();

        // Move the sprite
        if (App.GetInput().IsKeyDown(sf::Key::Left))  Sprite.Move(-100 * ElapsedTime, 0);
        if (App.GetInput().IsKeyDown(sf::Key::Right)) Sprite.Move( 100 * ElapsedTime, 0);
        if (App.GetInput().IsKeyDown(sf::Key::Up))    Sprite.Move(0, -100 * ElapsedTime);
        if (App.GetInput().IsKeyDown(sf::Key::Down))  Sprite.Move(0,  100 * ElapsedTime);

        // Rotate the sprite
        if (App.GetInput().IsKeyDown(sf::Key::Add))      Sprite.Rotate(- 100 * ElapsedTime);
        if (App.GetInput().IsKeyDown(sf::Key::Subtract)) Sprite.Rotate(+ 100 * ElapsedTime);

        // Clear screen
        App.Clear();

        // Display sprite in our window
        App.Draw(Sprite);

        // Display window contents on screen
        App.Display();
    }

    return EXIT_SUCCESS;
}

The only part of the code I changed was the file name for the sprite. If I build this linking sfml-graphics.lib I get an unhandled Access violation at the ReadFromFile() call, and a bunch of jibberish is spit out of the console. If I like with sfml-graphics-d.lib, I get by the image loading part fine, but at the App.GetEvent(Event) call, I get another Access violation unhandled exception.

Am I doing something wrong? Is this a bug? Whats the deal? Thanks a lot for your help.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Unhandled exceptions thrown from sprite tutorial
« Reply #1 on: March 23, 2009, 07:52:40 am »
You're probably mixing different configurations (debug / release), or using the wrong libraries (VS2008 instead of VS2005, for example).
Laurent Gomila - SFML developer

Chadwell

  • Newbie
  • *
  • Posts: 5
    • View Profile
Unhandled exceptions thrown from sprite tutorial
« Reply #2 on: March 23, 2009, 02:34:41 pm »
Quote from: "Laurent"
You're probably mixing different configurations (debug / release), or using the wrong libraries (VS2008 instead of VS2005, for example).


Ahhh, You are right. I was linking in sfml-system.lib, sfml-Window.lib, and sfml-graphics-d.lib. Once I changed system and Window to -d.lib it worked perfectly.

I must ask, since using all of the non-debug libs at the same time didn't work, do the debug libs HAVE to be used if you are compiling with Visual Studio in debug mode? If I missed that in the tutorial I apologize, but if it isn't in there it might be something useful to add.

Thanks a lot for your help!

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Unhandled exceptions thrown from sprite tutorial
« Reply #3 on: March 23, 2009, 03:13:42 pm »
Quote
do the debug libs HAVE to be used if you are compiling with Visual Studio in debug mode?

Yes.

Quote
If I missed that in the tutorial I apologize, but if it isn't in there it might be something useful to add

Actually, it is explained in the tutorials:
Quote
For the Debug configuration, you can link with the debug versions of the libraries, which have the "-d" suffix (sfml-system-d.lib in this case)

I should probably say "you must" instead of "you can" :)
Laurent Gomila - SFML developer

Chadwell

  • Newbie
  • *
  • Posts: 5
    • View Profile
Unhandled exceptions thrown from sprite tutorial
« Reply #4 on: March 23, 2009, 08:29:13 pm »
Quote from: "Laurent"
Quote
do the debug libs HAVE to be used if you are compiling with Visual Studio in debug mode?

Yes.

Quote
If I missed that in the tutorial I apologize, but if it isn't in there it might be something useful to add

Actually, it is explained in the tutorials:
Quote
For the Debug configuration, you can link with the debug versions of the libraries, which have the "-d" suffix (sfml-system-d.lib in this case)

I should probably say "you must" instead of "you can" :)

Yep, that was the part that confused me, I thought the "can" implied it was an option. That change would make it a lot clearer.

Thanks a lot for your help I appreciate it!

 

anything