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

Author Topic: SFML with Visual Studio 2013 - Program Crash at texture load  (Read 3151 times)

0 Members and 1 Guest are viewing this topic.

JayhawkZombie

  • Jr. Member
  • **
  • Posts: 76
    • View Profile
SFML with Visual Studio 2013 - Program Crash at texture load
« on: April 02, 2015, 10:26:01 pm »
Hi, all.
I can't seem to get SFML 2.2 to work in Visual Studio. I've gotten 2.1 to work, so I'm not sure what I'm doing incorrectly.
There seems to be an issue when I try to load a texture from a file.  I've made sure that the file is actually in the directory.
The console absolutely freaks out when the texture load function is called, and I get the usual "Your program has stopped working" error from Windows, which is useless because it gives no reasoning as to why.

The SFML sample of drawing a green circle works fine.

These are my Visual Studio settings:

C++/General
Additional Include Directories: C:\SFML\SFML-2.2-32\include
Linker/General
Additional Library Directories: C:\SFML\SFML-2.2-32\lib
Linker/Input
Additional Dependencies: sfml-graphics.lib
sfml-window.lib
sfml-system.lib
sfml-audio.lib
sfml-network.lib

I have copied all the DLL files to my project's directory.
I don't have any pre-processor settings set.

This is the code I'm using:

#include <iostream>

#include <SFML/System.hpp>
#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>

int main()
{
   sf::RenderWindow window(sf::VideoMode(500, 500), "SFML works!");
   sf::CircleShape shape(100.f);
   shape.setFillColor(sf::Color::Green);

   sf::Sprite sprite;
   sf::Texture texture;
   

   //The program freaks out here
   //a bunch of incoherent stuff outputs from the console and the application freezes
   if (!texture.loadFromFile("sfml-logo-big.bmp"))
   {

   }

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

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

   return 0;
}


The output from the console when it crashes is just thousands of random, incoherent characters - kind of like what you'd see if you tried to look an encrypted file.

Did I mess up setting this up?  I thought I set it up correctly, since the drawing of a green circle works fine.

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: SFML with Visual Studio 2013 - Program Crash at texture load
« Reply #1 on: April 02, 2015, 10:29:12 pm »
Are you perhaps mixing debug and release builds of your application/sfml? If so, expect strange errors.
Are you using the exact same compiler that was used to build your version of SFML to build your application? If not, expect strange errors.

JayhawkZombie

  • Jr. Member
  • **
  • Posts: 76
    • View Profile
Re: SFML with Visual Studio 2013 - Program Crash at texture load
« Reply #2 on: April 02, 2015, 11:00:01 pm »
Thanks for the reply.
I don't think I'm mixing the two, but I'm not 100%.  How can I check to make sure I'm not mixing them up?

I'm using the compiler that comes with VS 2013 Professional Update 2, which I think is the same one used to build the VS 2013 version of SFML.

Oh, you know what, I'm using Visual C++ 2013, and SFML looks like it was built for Visual C++ 2012.  It looks like I might have to build SFML myself.

Rosme

  • Full Member
  • ***
  • Posts: 169
  • Proud member of the shoe club
    • View Profile
    • Code-Concept
Re: SFML with Visual Studio 2013 - Program Crash at texture load
« Reply #3 on: April 02, 2015, 11:06:35 pm »
The libraries you link to in debug finish with -d where as in release they don't. The ones you said you link to would be release.
GitHub
Code Concept
Twitter
Rosme on IRC/Discord

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: SFML with Visual Studio 2013 - Program Crash at texture load
« Reply #4 on: April 02, 2015, 11:06:41 pm »
Thanks for the reply.
I don't think I'm mixing the two, but I'm not 100%.  How can I check to make sure I'm not mixing them up?
The debug libraries (which you should use for a debug build of your app) end in "-d", the release ones (which you should use for a release build) do not.

I'm using the compiler that comes with VS 2013 Professional Update 2, which I think is the same one used to build the VS 2013 version of SFML.

Oh, you know what, I'm using Visual C++ 2013, and SFML looks like it was built for Visual C++ 2012.  It looks like I might have to build SFML myself.
If that's indeed the case - building your app with VC 2013 and linking with SFML built with VC 2012 - then it's not surprising you are having strange problems.

Building the library yourself with the same compiler used to build your application is always the best way to avoid this kind of problem. And don't worry; it's easy  :)

EDIT: Another thing that's always worth doing is updating your graphics card drivers. Newer SFML versions use new functionality compared to older versions and your (old) drivers may just not be able to deal with it.
« Last Edit: April 02, 2015, 11:37:36 pm by Jesper Juhl »