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.