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

Author Topic: RenderWindow::PollEvent + mouse movement problem  (Read 3474 times)

0 Members and 1 Guest are viewing this topic.

olie258

  • Newbie
  • *
  • Posts: 5
    • View Profile
RenderWindow::PollEvent + mouse movement problem
« on: November 04, 2011, 08:03:00 pm »
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):
Code: [Select]
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):
Code: [Select]
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.

Code: [Select]
#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;
}

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
RenderWindow::PollEvent + mouse movement problem
« Reply #1 on: November 04, 2011, 08:18:36 pm »
Do you have a high-resolution mouse?
Do you have a joystick?
Laurent Gomila - SFML developer

olie258

  • Newbie
  • *
  • Posts: 5
    • View Profile
RenderWindow::PollEvent + mouse movement problem
« Reply #2 on: November 04, 2011, 08:48:40 pm »
Hi, Laurent,

Thanks for the speedy reply. I'm not entirely sure what is meant by a 'high resolution mouse", but according to this page on Logitech's site the DPI is 1000. It certainly wasn't sold as high performance kit, just your average, cheapish keyboard/mouse combo.

I have a joystick (an Xbox 360 controller connected via a wireless adaptor) but this hasn't been powered up or connected whilst running the application. The driver does run a process in the background though.

Cheers,
Olie.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
RenderWindow::PollEvent + mouse movement problem
« Reply #3 on: November 04, 2011, 08:56:14 pm »
I think it's the same problem as here:
http://www.sfml-dev.org/forum/viewtopic.php?t=6079

(workarounds included)
Laurent Gomila - SFML developer

olie258

  • Newbie
  • *
  • Posts: 5
    • View Profile
RenderWindow::PollEvent + mouse movement problem
« Reply #4 on: November 04, 2011, 09:41:50 pm »
Ah, should have spotted that thread myself. I haven't tried the fix yet but that looks promising (I'll report back if it doesn't work). Thanks for the help.