SFML community forums

Help => Graphics => Topic started by: Chiggy_Playz on April 15, 2019, 01:28:23 pm

Title: Failed to load image.
Post by: Chiggy_Playz on April 15, 2019, 01:28:23 pm
so i am very new to SFML (less then 24 hrs) and i have encountered with a weird problem. I am trying to load a texture and when i run my code, the cmd shows "failed to load ... " in the very beginning and then prints all sort of weird random gibberish stuff. I am using visual studio 2017 and SFML 2.5 . Also i found my working dir by using system(dir) and placed my png there but still doesnt work. also if i remove the "if condition" everything is fine. Here is my code :
#include <SFML/Graphics.hpp>
#include "iostream";
 using namespace std;
 using namespace sf;
 int main()
 {
    RenderWindow window(VideoMode(1000, 1000), "Chiggy's Tic Tac Toe!");
    CircleShape shape(100.f);
    shape.setFillColor(Color::Blue);
    Texture texture;
    if (!texture.loadFromFile("D:\Developement\VisualStudio\sfml\try\Project0\Project0\mad.png")) {  
         
           cout<<"Mario failed to load horribly"<<endl; system("pause"); //return EXIT_FAILURE; }

     while (window.isOpen()) {

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

 window.clear(Color::Black);
 window.draw(shape);
 window.display();
}
return 0; }
Title: Re: Failed to load image.
Post by: G. on April 15, 2019, 01:40:18 pm
Most likely you're linking the debug SFML in release mode, or the release SFML in debug mode.
Title: Re: Failed to load image.
Post by: Laurent on April 15, 2019, 01:56:59 pm
Also, use \\ or / in string literals. The single back-slash is used for escape sequences.
Title: Re: Failed to load image.
Post by: Chiggy_Playz on April 15, 2019, 02:12:32 pm
Also, use \\ or / in string literals. The single back-slash is used for escape sequences.

didnt work i did try it. still shows the things i have linked in the attachment. also the white thing that you see on the right side is the windows which is supposed to be black.

Title: Re: Failed to load image.
Post by: Chiggy_Playz on April 15, 2019, 02:13:52 pm
Most likely you're linking the debug SFML in release mode, or the release SFML in debug mode.

What do you mean? how do i solve this? Also i have attached a picture so as to explain what i get.
Title: Re: Failed to load image.
Post by: Laurent on April 15, 2019, 02:24:50 pm
Don't link to sfml-xxx.lib (release libraries) when you build in Debug mode. It should be sfml-xxx-d.lib (debug libraries).

(https://en.sfml-dev.org/forums/index.php?action=dlattach;topic=25279.0;attach=4200)
Title: Re: Failed to load image.
Post by: Chiggy_Playz on April 15, 2019, 02:29:00 pm
Don't link to sfml-xxx.lib (release libraries) when you build in Debug mode. It should be sfml-xxx-d.lib (debug libraries).

(https://en.sfml-dev.org/forums/index.php?action=dlattach;topic=25279.0;attach=4200)


Actuall i am the biggest noob in this universe and dont know the difference. all i know i did is I followed how to install on wikihow. Here is the link

https://www.wikihow.com/Set-Up-SFML-in-a-Project-on-Visual-Studio-2017
Title: Re: Failed to load image.
Post by: Laurent on April 15, 2019, 02:36:32 pm
If you're "the biggest noob in this universe", then let me give you a very important advice: always start with the official tutorials, not some random stuff on a general how-to website.

We've spent a lot of time writing detailed tutorials, with screen captures, that address the most common mistakes -- you see, this one is even in a red box. So please read our tutorials before asking anything.
Title: Re: Failed to load image.
Post by: Chiggy_Playz on April 15, 2019, 07:19:30 pm
Don't link to sfml-xxx.lib (release libraries) when you build in Debug mode. It should be sfml-xxx-d.lib (debug libraries).

(https://en.sfml-dev.org/forums/index.php?action=dlattach;topic=25279.0;attach=4200)

this worked. firstly i checked the libraries, I found that i had installed sfml-graphics along with sfml-graphics-d

then i changed my config from build to release and voila it worked. thanx a lot man. appreciate it.