SFML community forums
Help => Graphics => Topic started by: Stewbond on October 08, 2011, 01:47:45 pm
-
Hello,
I'm on my second day of learning SFML. I got through the window tutorial without issue, however I am having problems with the graphics tutorial. Sample code from the sprites tutorial is given below. I can compile this without issue, however when I run this, the program crashes when I use App.GetEvent(Event)
App.Clear()
App.Display()
App.Close()
These worked fine when App was defined as sf::Window but doesn't work with sf::RenderWindow. I've read through the forums a bit and found that someone had a similar problems which were solved by updating their video card driver. I've run other games on this PC with more complicated graphics so I'm not sure why my video-card would not work for this very specific case. Regardless I've tried updating my driver and found that it is the most recent one available. I've also read that someone needed to re-compile SFML 1.6 for VC++ 2010 because his definition of the RenderWindow didn't work. I'm not sure quite how to do that, but my RenderWindow definition works so I don't think that is the problem.
Does anyone have any ideas? I am running SFML 1.6 (built for VC++ 2008) with MS Visual C++ 2010 in Windows 7. I'm compiling in Debug mode. I'm using the SFML release libraries and DLLs. My video card is an NVIDIA GeForce 8600 GT with NVIDIA driver version 8.17.12.6099.
#include <SFML/Graphics.hpp>
int main()
{
sf::RenderWindow App(sf::VideoMode(800, 600, 32), "SFML Graphics");
sf::Image Image;
if (!Image.LoadFromFile(".//Images//Katie.png")) //This file exists and is loaded.
return EXIT_FAILURE;
sf::Sprite Sprite(Image);
Sprite.SetColor(sf::Color(0, 255, 255, 128));
Sprite.SetPosition(200.f, 100.f);
Sprite.SetScale(2.f, 2.f);
while (App.IsOpened())
{
sf::Event Event;
while (App.GetEvent(Event)) // This line crashes
if (Event.Type == sf::Event::Closed) App.Close();
float ElapsedTime = App.GetFrameTime();
if (App.GetInput().IsKeyDown(sf::Key::Left)) Sprite.Move(-100 * ElapsedTime, 0);
if (App.GetInput().IsKeyDown(sf::Key::Right)) Sprite.Move( 100 * ElapsedTime, 0);
App.Clear(); // This line crashes
App.Draw(Sprite);
App.Display(); // This line crashes
}
return EXIT_SUCCESS;
}
[EDIT:] Here is the debug error provided by Visual Studio's Debug tool:
A buffer overrun has occurred in GraphicsTutorial.exe which has corrupted the program's internal state.
-
The advice to recompile SFML for Visual Studio 2010 is true, because the VS 2008 libraries are not compatible. You can download the SDK, open the .sln solution for VS 2008, convert the project to VS 2010, and recompile everything.
Alternatively, you can directly start with SFML 2 and CMake. The advantage is, there are a lot of bugfixes, new features and you don't have to change your code when you eventually port projects to the new version ;)
-
I've spent the last 10 hours attempting to get a compiled version of SFML with Visual C++ and so far I am unsuccessful.
CMake was actually pretty easy to use. The actual compilation went okay without errors (except that my DLLs all have a "-2" suffix).
My problem now is I can't compile my current code with the headers included in the SFML 2.0 package.
It gives me errors such as GetEvent() is not a member of sf::Window or sf::RenderWindow. When I compare the headers from 1.6 and 2.0, I find that these definitions are indeed missing. Therefore it appears that the SFML 1.6 code that I've taken from the tutorial is not compatible with SFML 2.0.
I've reverted back to SFML 1.6 because I can compile my code now. The problem still remains that it was built using VC++ 2008 while I am using 2010. I am thinking of just installing Visual Studio 2008 but I need to confirm that this is the problem.
Like I said earlier, the other guy who used 2010 had his problems with the sf::RenderWindow App() line. I don't have my problem in the same spot so it may not be the same issue.
Are there any other potential things I could try before I take this step?
-
Therefore it appears that the SFML 1.6 code that I've taken from the tutorial is not compatible with SFML 2.0.
Of course, 1.6 and 2.0 are a lot different. There's a list of modifications in the general forum.
The problem still remains that it was built using VC++ 2008 while I am using 2010
Yes, and you still need to recompile it with Visual C++ 2010 ;)
It's even easier with SFML 1.6, Visual studio solutions are provided directly. You just have to open them, let the assistant convert from 2008 to 2010, and compile.
-
Ah ha!
I just recompiled SFML 1.6 by opening the .SLN file and then playing around a bit. I've got everything working with is static libraries and the release DLLs. This was my first time compiling someone else's solution so it took me a little while.
The Rendering Window tutorial now runs properly!
-
Can you give some instructions of what you did?
I'm having a similar problem. I can compile the 'graphics solution', but at run time it crashes. The debugger points to the App.Display(); line. If I comment it, along with the App.Clear(sf::Color(200, 0, 0));, that also gives problems, the program runs.
I get: Unhandled exception at 0x00c29515 in NEW GAME.exe: 0xC0000005: Access violation reading location 0x42c80010.
Thank you.
-
I'm having problems too, and I'm starting to have enough...
I've tried several different IDE, Visual Studio 2008, Visual Studio 2010 and Code::Blocks and none of them will open the graphics window. They only open the console window and that's it. I've tried building the SFML solution with VS2010 but it didn't help. And I have everything linked correctly in each IDE and it builds fine. Running the program isn't working.
If someone could tell me what to do, it would be great.
To add some more mystery into this is that it worked last week just fine when I was using sfml library
-
Don't forget the ATI bug, with SFML 1.6 and dynamic SFML libraries on Windows.
If this is it, switch to static libraries or to SFML 2.
-
Don't forget the ATI bug, with SFML 1.6 and dynamic SFML libraries on Windows.
If this is it, switch to static libraries or to SFML 2.
tried to compile it with static and dll both but didn't help, I'll give 2.0 a go
-
tried to compile it with static and dll both but didn't help
Can you explain what you did exactly?
-
tried to compile it with static and dll both but didn't help
Can you explain what you did exactly?
I opened the SFML.sln project from SFML-1.6\build\vc2008 directory with VS2010 Premium. Let it port the solution from 2008 to 2010, deleted the examples so that there was left sfml-audio, sfml-graphics, sfml-main, sfml-network, sfml-system and sfml-window in the project. Then I chose "Debug DLL" and "Build", "Release DLL" and "Build" and tried to run a program.
#include <SFML/Graphics.hpp>
int main()
{
sf::RenderWindow window(sf::VideoMode(800, 600, 32), "Window");
while(window.IsOpened())
{
sf::Event Event;
while(window.GetEvent(Event))
{
if(Event.Type == sf::Event::Closed)
{
window.Close();
}
}
window.Clear();
window.Display();
}
return EXIT_SUCCESS;
}
I couldn't get the window to show so I opened the same SFML solution again and chose "Debug static" "Rebuild" "Release static" "Rebuild" and tried again but it didn't work.
-
Ok, now I had little patience when running the program in debug mode and the graphics window popped up about 10-15 seconds after I had started the program and works fine, but every time I run the program I have to wait for that 10-15 seconds???
and this is when I'm using VS2008
-
Windows 7?
-
Yes, Windows 7 Professional 64-bit Version 6.1 (Build 7601: Service Pack 1)
-
Other people seem to have a similar problem on Windows 7. I also have Windows 7, but everything works fine for me.
Have you tried SFML 2 yet?
-
I tried but I couldn't get it installed, I just don't know what to do
Now that you've chosen the build directory, there's one more thing to do before you can run CMake. When CMake configures your project, it tests the availability of the compiler (and checks its version as well). As a consequence, the compiler executable must be available when CMake is run. This is not a problem for Linux and Mac OS X users, since the compilers are installed in a standard path and are always globally available, but on Windows you may have to add the directory of your compiler in the PATH environment variable, so that CMake can find it automatically. This is especially important when you have several compilers installed, or multiple versions of the same compiler.
On Windows, if you want to use gcc (MinGW), you can temporarily add the MinGW\bin directory to the PATH and then run cmake from the command shell:
> set PATH=%PATH%;your_mingw_folder\bin
> cmake
With Visual C++, you can either run CMake from the "Visual Studio command prompt" available from the start menu, or call the vcvars32.bat file of your Visual Studio installation; it will setup the environment variables properly.
> your_visual_studio_folder\VC\bin\vcvars32.bat
> cmake
I don't understand what I'm supposed to do in this part
-
Open a console, and type the given commands. Replace "cmake" with "cmake-gui" if you want to use the GUI version of CMake.