Hi guys,
I ported the game I'm working on to SFML 2.0 today (from version 1.6) and I'm seeing a problem that was not happening before. When the mouse cursor is moved over my application's window the framerate drops noticeably and sometimes the application actually freezes while the cursor is moving (in these cases the application resumes as normal once the mouse is still again but with one really long frame).
The problem occurs regardless of whether v-sync is enabled, in both full screen and windowed modes. I'm using the latest development snapshot of SFML 2.0 (downloaded yesterday) and I have been able to reproduce this problem.
The only solution I've found is to remove the call to PollEvent from my game loop.
Before (problem occurs):
void Game::start()
{
while (pMainWindow->IsOpened())
{
// handle window events
sf::Event e;
while (pMainWindow->PollEvent(e))
{
if (e.Type == sf::Event::Closed)
{
pMainWindow->Close();
}
}
update();
draw();
}
}
After (works as normal):
void Game::start()
{
while (running)
{
update();
draw();
}
}
Without the call to PollEvent the application runs just as it did when on 1.6 (except for closing, of course). I'm wondering whether this is a bug or am I now using something incorrectly? Any suggestions would be much appreciated.
If anyone's interested here's my minimal recreation of the issue (although I've got a feeling that this would be known if it was a problem for everyone). When I run this code the speed at which the circle moves can be seen to drop whenever the mouse is over the window and is moved.
#include <SFML\Graphics.hpp>
int main()
{
sf::RenderWindow Window(sf::VideoMode(800, 600, 32), "SFML 2");
sf::Shape shape = sf::Shape::Circle(sf::Vector2f(0, 300), 40, sf::Color::Blue);
int x = 0;
while (Window.IsOpened())
{
sf::Event e;
while (Window.PollEvent(e))
{
if (e.Type == sf::Event::Closed)
{
Window.Close();
}
}
Window.Clear(sf::Color(107, 101, 237));
shape.SetX(x++ % 800);
Window.Draw(shape);
Window.Display();
}
return 0;
}