SFML community forums

Help => Graphics => Topic started by: WDR on June 22, 2013, 05:30:47 pm

Title: Unable to draw sprite
Post by: WDR on June 22, 2013, 05:30:47 pm
I am unable to draw a sprite from the sf::Texture and sf::Sprite classes. All the libraries are linked, all the dll's are placed correctly and even the image is in the right location. The image is also the same size as the window. The code also has no errors. Why am I getting an exception?  :(

Here's the code:
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>

int main()
{
        sf::RenderWindow window(sf::VideoMode(1024,768), "Window");
        sf::Texture image;
        if(!image.loadFromFile("images/splash.jpg"))
        {
                return 0;
        }
        sf::Sprite sprite(image);
        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;
}

Here's the exception:
Code: [Select]
'Image.exe': Loaded 'C:\Users\WDR\Documents\Visual Studio 2010\Projects\Image\Debug\Image.exe', Symbols loaded.
'Image.exe': Loaded 'C:\Windows\System32\ntdll.dll', Cannot find or open the PDB file
'Image.exe': Loaded 'C:\Windows\System32\kernel32.dll', Cannot find or open the PDB file
'Image.exe': Loaded 'C:\Windows\System32\KernelBase.dll', Cannot find or open the PDB file
'Image.exe': Loaded 'C:\Users\WDR\Documents\Visual Studio 2010\Projects\Image\Debug\sfml-graphics-2.dll', Binary was not built with debug information.
'Image.exe': Loaded 'C:\Users\WDR\Documents\Visual Studio 2010\Projects\Image\Debug\sfml-window-2.dll', Binary was not built with debug information.
'Image.exe': Loaded 'C:\Users\WDR\Documents\Visual Studio 2010\Projects\Image\Debug\sfml-system-2.dll', Binary was not built with debug information.
'Image.exe': Loaded 'C:\Windows\System32\msvcr100.dll', Cannot find or open the PDB file
'Image.exe': Loaded 'C:\Windows\System32\msvcp100.dll', Cannot find or open the PDB file
'Image.exe': Loaded 'C:\Windows\System32\opengl32.dll', Cannot find or open the PDB file
'Image.exe': Loaded 'C:\Windows\System32\msvcrt.dll', Cannot find or open the PDB file
'Image.exe': Loaded 'C:\Windows\System32\advapi32.dll', Cannot find or open the PDB file
'Image.exe': Loaded 'C:\Windows\System32\sechost.dll', Cannot find or open the PDB file
'Image.exe': Loaded 'C:\Windows\System32\rpcrt4.dll', Cannot find or open the PDB file
'Image.exe': Loaded 'C:\Windows\System32\gdi32.dll', Cannot find or open the PDB file
'Image.exe': Loaded 'C:\Windows\System32\user32.dll', Cannot find or open the PDB file
'Image.exe': Loaded 'C:\Windows\System32\lpk.dll', Cannot find or open the PDB file
'Image.exe': Loaded 'C:\Windows\System32\usp10.dll', Cannot find or open the PDB file
'Image.exe': Loaded 'C:\Windows\System32\glu32.dll', Cannot find or open the PDB file
'Image.exe': Loaded 'C:\Windows\System32\ddraw.dll', Cannot find or open the PDB file
'Image.exe': Loaded 'C:\Windows\System32\dciman32.dll', Cannot find or open the PDB file
'Image.exe': Loaded 'C:\Windows\System32\setupapi.dll', Cannot find or open the PDB file
'Image.exe': Loaded 'C:\Windows\System32\cfgmgr32.dll', Cannot find or open the PDB file
'Image.exe': Loaded 'C:\Windows\System32\oleaut32.dll', Cannot find or open the PDB file
'Image.exe': Loaded 'C:\Windows\System32\ole32.dll', Cannot find or open the PDB file
'Image.exe': Loaded 'C:\Windows\System32\devobj.dll', Cannot find or open the PDB file
'Image.exe': Loaded 'C:\Windows\System32\dwmapi.dll', Cannot find or open the PDB file
'Image.exe': Loaded 'C:\Windows\System32\winmm.dll', Cannot find or open the PDB file
'Image.exe': Loaded 'C:\Windows\System32\msvcp100d.dll', Symbols loaded.
'Image.exe': Loaded 'C:\Windows\System32\msvcr100d.dll', Symbols loaded.
'Image.exe': Loaded 'C:\Windows\System32\imm32.dll', Cannot find or open the PDB file
'Image.exe': Loaded 'C:\Windows\System32\msctf.dll', Cannot find or open the PDB file
'Image.exe': Loaded 'C:\Windows\System32\uxtheme.dll', Cannot find or open the PDB file
'Image.exe': Loaded 'C:\Windows\System32\nvoglv32.dll', Cannot find or open the PDB file
'Image.exe': Loaded 'C:\Windows\System32\shell32.dll', Cannot find or open the PDB file
'Image.exe': Loaded 'C:\Windows\System32\shlwapi.dll', Cannot find or open the PDB file
'Image.exe': Loaded 'C:\Windows\System32\version.dll', Cannot find or open the PDB file
'Image.exe': Loaded 'C:\Windows\System32\wintrust.dll', Cannot find or open the PDB file
'Image.exe': Loaded 'C:\Windows\System32\crypt32.dll', Cannot find or open the PDB file
'Image.exe': Loaded 'C:\Windows\System32\msasn1.dll', Cannot find or open the PDB file
'Image.exe': Loaded 'C:\Windows\System32\ntmarta.dll', Cannot find or open the PDB file
'Image.exe': Loaded 'C:\Windows\System32\Wldap32.dll', Cannot find or open the PDB file
'Image.exe': Loaded 'C:\Windows\System32\powrprof.dll', Cannot find or open the PDB file
The thread 'Win32 Thread' (0x1904) has exited with code 0 (0x0).
'Image.exe': Unloaded 'C:\Windows\System32\powrprof.dll'
The thread 'Win32 Thread' (0xe38) has exited with code 0 (0x0).
The thread 'Win32 Thread' (0x6c8) has exited with code 0 (0x0).
The thread 'Win32 Thread' (0xe5c) has exited with code 0 (0x0).
'Image.exe': Loaded 'C:\Windows\System32\dinput.dll', Cannot find or open the PDB file
'Image.exe': Loaded 'C:\Windows\System32\hid.dll', Cannot find or open the PDB file
'Image.exe': Loaded 'C:\Windows\System32\cryptbase.dll', Cannot find or open the PDB file
First-chance exception at 0x706b1f34 in Image.exe: 0xC0000005: Access violation reading location 0x00b15000.
Unhandled exception at 0x706b1f34 in Image.exe: 0xC0000005: Access violation reading location 0x00b15000.
The program '[7988] Image.exe: Native' has exited with code -1073741819 (0xc0000005).
Title: Re: Unable to draw sprite
Post by: Laurent on June 22, 2013, 05:34:34 pm
Because you use the release version of the SFML libraries in debug mode. And because you didn't read the tutorial :(
Title: Re: Unable to draw sprite
Post by: WDR on June 22, 2013, 05:57:06 pm
Okay... I included all dll's and linked all lib's. Still throwing me an exception.

Code: [Select]
'Image.exe': Loaded 'C:\Users\WDR\Documents\Visual Studio 2010\Projects\Image\Debug\Image.exe', Symbols loaded.
'Image.exe': Loaded 'C:\Windows\System32\ntdll.dll', Cannot find or open the PDB file
'Image.exe': Loaded 'C:\Windows\System32\kernel32.dll', Cannot find or open the PDB file
'Image.exe': Loaded 'C:\Windows\System32\KernelBase.dll', Cannot find or open the PDB file
'Image.exe': Loaded 'C:\Users\WDR\Documents\Visual Studio 2010\Projects\Image\Debug\sfml-graphics-2.dll', Binary was not built with debug information.
'Image.exe': Loaded 'C:\Users\WDR\Documents\Visual Studio 2010\Projects\Image\Debug\sfml-window-2.dll', Binary was not built with debug information.
'Image.exe': Loaded 'C:\Users\WDR\Documents\Visual Studio 2010\Projects\Image\Debug\sfml-system-2.dll', Binary was not built with debug information.
'Image.exe': Loaded 'C:\Windows\System32\msvcr100.dll', Cannot find or open the PDB file
'Image.exe': Loaded 'C:\Windows\System32\msvcp100.dll', Cannot find or open the PDB file
'Image.exe': Loaded 'C:\Windows\System32\opengl32.dll', Cannot find or open the PDB file
'Image.exe': Loaded 'C:\Windows\System32\msvcrt.dll', Cannot find or open the PDB file
'Image.exe': Loaded 'C:\Windows\System32\advapi32.dll', Cannot find or open the PDB file
'Image.exe': Loaded 'C:\Windows\System32\sechost.dll', Cannot find or open the PDB file
'Image.exe': Loaded 'C:\Windows\System32\rpcrt4.dll', Cannot find or open the PDB file
'Image.exe': Loaded 'C:\Windows\System32\gdi32.dll', Cannot find or open the PDB file
'Image.exe': Loaded 'C:\Windows\System32\user32.dll', Cannot find or open the PDB file
'Image.exe': Loaded 'C:\Windows\System32\lpk.dll', Cannot find or open the PDB file
'Image.exe': Loaded 'C:\Windows\System32\usp10.dll', Cannot find or open the PDB file
'Image.exe': Loaded 'C:\Windows\System32\glu32.dll', Cannot find or open the PDB file
'Image.exe': Loaded 'C:\Windows\System32\ddraw.dll', Cannot find or open the PDB file
'Image.exe': Loaded 'C:\Windows\System32\dciman32.dll', Cannot find or open the PDB file
'Image.exe': Loaded 'C:\Windows\System32\setupapi.dll', Cannot find or open the PDB file
'Image.exe': Loaded 'C:\Windows\System32\cfgmgr32.dll', Cannot find or open the PDB file
'Image.exe': Loaded 'C:\Windows\System32\oleaut32.dll', Cannot find or open the PDB file
'Image.exe': Loaded 'C:\Windows\System32\ole32.dll', Cannot find or open the PDB file
'Image.exe': Loaded 'C:\Windows\System32\devobj.dll', Cannot find or open the PDB file
'Image.exe': Loaded 'C:\Windows\System32\dwmapi.dll', Cannot find or open the PDB file
'Image.exe': Loaded 'C:\Windows\System32\winmm.dll', Cannot find or open the PDB file
'Image.exe': Loaded 'C:\Windows\System32\msvcp100d.dll', Symbols loaded.
'Image.exe': Loaded 'C:\Windows\System32\msvcr100d.dll', Symbols loaded.
'Image.exe': Loaded 'C:\Windows\System32\imm32.dll', Cannot find or open the PDB file
'Image.exe': Loaded 'C:\Windows\System32\msctf.dll', Cannot find or open the PDB file
'Image.exe': Loaded 'C:\Windows\System32\uxtheme.dll', Cannot find or open the PDB file
'Image.exe': Loaded 'C:\Windows\System32\nvoglv32.dll', Cannot find or open the PDB file
'Image.exe': Loaded 'C:\Windows\System32\shell32.dll', Cannot find or open the PDB file
'Image.exe': Loaded 'C:\Windows\System32\shlwapi.dll', Cannot find or open the PDB file
'Image.exe': Loaded 'C:\Windows\System32\version.dll', Cannot find or open the PDB file
'Image.exe': Loaded 'C:\Windows\System32\wintrust.dll', Cannot find or open the PDB file
'Image.exe': Loaded 'C:\Windows\System32\crypt32.dll', Cannot find or open the PDB file
'Image.exe': Loaded 'C:\Windows\System32\msasn1.dll', Cannot find or open the PDB file
'Image.exe': Loaded 'C:\Windows\System32\ntmarta.dll', Cannot find or open the PDB file
'Image.exe': Loaded 'C:\Windows\System32\Wldap32.dll', Cannot find or open the PDB file
'Image.exe': Loaded 'C:\Windows\System32\powrprof.dll', Cannot find or open the PDB file
'Image.exe': Unloaded 'C:\Windows\System32\powrprof.dll'
The thread 'Win32 Thread' (0x1670) has exited with code 0 (0x0).
The thread 'Win32 Thread' (0x1f80) has exited with code 0 (0x0).
The thread 'Win32 Thread' (0x1f38) has exited with code 0 (0x0).
The thread 'Win32 Thread' (0x1b14) has exited with code 0 (0x0).
'Image.exe': Loaded 'C:\Windows\System32\dinput.dll', Cannot find or open the PDB file
'Image.exe': Loaded 'C:\Windows\System32\hid.dll', Cannot find or open the PDB file
'Image.exe': Loaded 'C:\Windows\System32\cryptbase.dll', Cannot find or open the PDB file
First-chance exception at 0x706b1f34 in Image.exe: 0xC0000005: Access violation reading location 0x00705000.
Unhandled exception at 0x706b1f34 in Image.exe: 0xC0000005: Access violation reading location 0x00705000.
The program '[8180] Image.exe: Native' has exited with code -1073741819 (0xc0000005).
Title: Re: Unable to draw sprite
Post by: Nexus on June 22, 2013, 07:31:03 pm
Okay... I included all dll's and linked all lib's. Still throwing me an exception.
That's not the solution to the problem described by Laurent.

You are supposed to link the correct libraries, not all of them. Which ones, is written in the tutorial...
Title: Re: Unable to draw sprite
Post by: WDR on June 22, 2013, 07:50:49 pm
 :D That's what I meant also... I linked all the correct and required libraries. Still throws me the exception.

Edit: Works now but only works when I execute via the .exe file in the debug/release folder(s). Not working when I execute via Visual Studio 2010 in both modes. Says it failed to load image. But the .exe files load the image perfectly fine.
Title: Re: Unable to draw sprite
Post by: Laurent on June 22, 2013, 08:28:45 pm
This is also explained in the tutorials.

By the way, according to your output you're still doing it wrong, I don't know how it can work. Hint: the relevant paragraph is inside a big red box in the "Getting started" tutorial.
Title: Re: Unable to draw sprite
Post by: WDR on June 22, 2013, 08:34:32 pm
Oh my God! I'm passing off as ignorant to you, aren't I? Haha... I did read all of the tutorials before I even started to code!  :D

It isn't throwing an exception anymore. I know what I did wrong with the linking of libraries. I still have the executing from Visual Studio problem though.
Title: Re: Unable to draw sprite
Post by: Laurent on June 23, 2013, 09:05:04 am
Quote
Oh my God! I'm passing off as ignorant to you, aren't I?
No, just as someone who made a stupid mistake or overlooked an important paragraph in the tutorial. Like almost everybody else ;)

Look:

Quote
'Image.exe': Loaded 'C:\Users\WDR\Documents\Visual Studio 2010\Projects\Image\Debug\sfml-graphics-2.dll', Binary was not built with debug information.
'Image.exe': Loaded 'C:\Users\WDR\Documents\Visual Studio 2010\Projects\Image\Debug\sfml-window-2.dll', Binary was not built with debug information.
'Image.exe': Loaded 'C:\Users\WDR\Documents\Visual Studio 2010\Projects\Image\Debug\sfml-system-2.dll', Binary was not built with debug information.

It's loading sfml-xxx-2.dll files, which means that you're still linking to Release libraries in Debug mode. Debug libraries are sfml-xxx-2-d.dll.