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

Author Topic: Can't seem to load an image from file (VS 2010)  (Read 8760 times)

0 Members and 1 Guest are viewing this topic.

Gonzo

  • Newbie
  • *
  • Posts: 4
    • View Profile
Can't seem to load an image from file (VS 2010)
« on: June 19, 2012, 08:36:47 pm »
I have bee trying to figure out why for ages now. But if i try to load a file from the disk (both for image and texture) and i just get an unhandled exception.

This is the code:

#include <SFML/Graphics.hpp>
#include <Windows.h>

int main()
{
    sf::RenderWindow window(sf::VideoMode(1024, 768), "SFML works!");

    sf::Text text("Hello SFML");
        sf::Texture texture;

        texture.loadFromFile("dude.jpg");

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

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

    TerminateProcess(GetCurrentProcess(), EXIT_SUCCESS);
}
 

After some searching I thought maybe recompiling was the answer, but it didn't change a thing =(.
Also i managed to create an image giving it a colour, height and width so it leads me to think that te file is just not being found.

Here is some other relevant stuff:

Exception
Code: [Select]
Unhandled exception at 0x653a1f34 in SMFLTEST2.exe: 0xC0000005: Access violation reading location 0x00277000.

Callstack
Code: [Select]
msvcr100.dll!653a1f34()
  [Frames below may be incorrect and/or missing, no symbols loaded for msvcr100.dll]
  msvcp100.dll!644c1153()
  msvcp100.dll!644c2635()
  sfml-graphics-2.dll!510e1ca6()
  sfml-graphics-2.dll!510f1b17()
  sfml-graphics-2.dll!510e5308()
  sfml-graphics-2.dll!510fb204()
> SMFLTEST2.exe!main()  Line 11 + 0x35 bytes C++
  SMFLTEST2.exe!_WinMain@16()  + 0x16 bytes C++
  SMFLTEST2.exe!__tmainCRTStartup()  Line 547 + 0x2c bytes C
  SMFLTEST2.exe!WinMainCRTStartup()  Line 371 C
  kernel32.dll!770d3677()
  ntdll.dll!77c99d72()
  ntdll.dll!77c99d45()


Gfx card: AMD Radeon 7850 with 12.4 CCC
« Last Edit: June 19, 2012, 10:42:34 pm by Laurent »

kingsman142

  • Newbie
  • *
  • Posts: 10
    • View Profile
Re: Can't seem to load an image from file (VS 2010)
« Reply #1 on: June 19, 2012, 09:25:53 pm »
The image has to be in your project folder.  Or, you can write the C: directory to the image like so:

Texture texture;
texture.loadFromFile("C:/Directory/To/Your/Image/image.jpg");
 
OS: Windows 7
SFML Version: 2
Compiler: Code::Blocks with MinGW

Gonzo

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Can't seem to load an image from file (VS 2010)
« Reply #2 on: June 19, 2012, 10:10:06 pm »
Thanks for the reply but i Just tried both of those methods and i am still getting the same thing =[

kingsman142

  • Newbie
  • *
  • Posts: 10
    • View Profile
Re: Can't seem to load an image from file (VS 2010)
« Reply #3 on: June 19, 2012, 10:17:27 pm »
Maybe dude.jpg is too large of a file.  Try loading a file that's smaller in size, or perhaps a png. 

And, make sure "dude" is actually a jpg.
OS: Windows 7
SFML Version: 2
Compiler: Code::Blocks with MinGW

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Can't seem to load an image from file (VS 2010)
« Reply #4 on: June 19, 2012, 10:44:44 pm »
Which SFML package did you download? Are you sure that you don't have another version? Have you followed the tutorial?

Quote
TerminateProcess(GetCurrentProcess(), EXIT_SUCCESS);
???
Laurent Gomila - SFML developer

Gonzo

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Can't seem to load an image from file (VS 2010)
« Reply #5 on: June 19, 2012, 10:58:49 pm »
Which SFML package did you download? Are you sure that you don't have another version? Have you followed the tutorial?

Quote
TerminateProcess(GetCurrentProcess(), EXIT_SUCCESS);
???

The code you put ?? next to is to stop getting an error after closing the window on debugging (i found in this thread: http://en.sfml-dev.org/forums/index.php?topic=3976.msg26066#msg26066)

Also firstly i was using the release candidate for version 2 that is on the website (for vs 2010) and when i compiled i used files from github. Both of wich produced this error.

Also dude.jpg is 10kb. Tried using a png and got the same outcome.

Thanks for the responses :)

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Can't seem to load an image from file (VS 2010)
« Reply #6 on: June 20, 2012, 08:11:10 am »
It seems like you're using release libraries in debug mode. Don't do that (it's written in the tutorial).
Laurent Gomila - SFML developer

Gonzo

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Can't seem to load an image from file (VS 2010)
« Reply #7 on: June 20, 2012, 09:13:57 am »
It seems like you're using release libraries in debug mode. Don't do that (it's written in the tutorial).

Wow i didn't even realise i was doing that and its one of the first things i checked. Doh.
Thanks for your replies, it seems to be working now - no crashes at least :)

 

anything