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

Author Topic: Strange stutter seemingly caused by pollEvent().  (Read 2853 times)

0 Members and 5 Guests are viewing this topic.

Khan95

  • Guest
Strange stutter seemingly caused by pollEvent().
« on: March 01, 2015, 02:11:10 pm »
I recently got into SFML and have played around with it quite a bit. I have noticed however that in all my tests there has been some kind of stutter. I was previously unable to figure out what caused it until I by chance commented out the while-loop which calls mWindow.pollEvent(). I first thought it was the way I was achieving a fixed timestep, but changing between an alternating and a fixed timestep did not have any effect on the stutter, or at least not as much as pollEvent() seems to have.

I am slightly suspicious though, considering I have looked far and wide for solutions and come up with close to nothing relating to specifically pollEvent. Here's a video demonstrating the issue.

https://www.youtube.com/watch?v=wrsGuczoIxQ&feature=youtu.be

Any ideas?
In case it's relevant, I use
Windows 7 Ultimate,
a 3,10 GHz 8-Core AMD,
8GB RAM
and a NVIDIA GeForce GTX 660Ti

// Starts the game loop
void Game::run()
{
        sf::Clock       gameTime;
        const float TimePerFrame = 1.f / 60.f;
        float           elapsedTime      = 0;
        while (mWindow.isOpen())
        {
                elapsedTime += gameTime.restart().asSeconds();
                while (elapsedTime > TimePerFrame)
                {
                        elapsedTime -= TimePerFrame;
                        handleEvents();
                        update(TimePerFrame);
                }
                draw();
        }
}

// Checks for and handles events
void Game::handleEvents()
{
        sf::Event event;
        while (mWindow.pollEvent(event))
        {
                switch (event.type)
                {
                case sf::Event::Closed:
                        mWindow.close();
                        break;
                }
        }
}

victorlevasseur

  • Full Member
  • ***
  • Posts: 206
    • View Profile
Re: Strange stutter seemingly caused by pollEvent().
« Reply #1 on: March 01, 2015, 06:50:03 pm »
Hi,

You have to handle events every frame. So, put handleEvents() outside of the while (elapsedTime > ...) block and it will work as expected.

Khan95

  • Guest
Re: Strange stutter seemingly caused by pollEvent().
« Reply #2 on: March 01, 2015, 08:43:51 pm »
Hi,

You have to handle events every frame. So, put handleEvents() outside of the while (elapsedTime > ...) block and it will work as expected.

Tried it and I still see the stutter :(. If it had any effect, it's barely noticable.

Khan95

  • Guest
Re: Strange stutter seemingly caused by pollEvent().
« Reply #3 on: March 03, 2015, 12:37:51 am »
I'm starting to suspect that this is just my computer. I tried it on my laptop and it seemed relatively fine.

So now I instead ask, if it's an issue with my computer, does anyone have any ideas why pollEvent would cause such a regular stutter on some computers? Thanks in advance!

Mario

  • SFML Team
  • Hero Member
  • *****
  • Posts: 879
    • View Profile
Re: Strange stutter seemingly caused by pollEvent().
« Reply #4 on: March 03, 2015, 01:11:42 am »
Maybe some driver issue? Any chance you're using a Logitech product? If so, try closing the Gaming Software (or anything similar) and then try again.

Khan95

  • Guest
Re: Strange stutter seemingly caused by pollEvent().
« Reply #5 on: March 03, 2015, 08:34:37 pm »
Maybe some driver issue? Any chance you're using a Logitech product? If so, try closing the Gaming Software (or anything similar) and then try again.

I have indeed been using a logitech product and had the "Gaming Software Profiler" running. Couldn't find how to shut it off initially but after a reboot (where my computer incidentally started a search for inconsistency in one of my harddrives) I did find it and turned it off. Now it seems to be running smoothly! I am however not very sure if it was fixed due to the reboot or shutting the software off :P.

Thanks a lot either way! I'm just really glad that I don't have to look at that awful nauseating stutter for now. I'll try to keep my eyes open if it should return! Once again, thanks!

Mario

  • SFML Team
  • Hero Member
  • *****
  • Posts: 879
    • View Profile
Re: Strange stutter seemingly caused by pollEvent().
« Reply #6 on: March 04, 2015, 12:06:32 pm »
Just start it again and try it? If you'd like to close it again, right click its icon in the system tray area (next to your taskbar clock) and pick the "Exit" option - or kill its process from within task manager.

Khan95

  • Guest
Re: Strange stutter seemingly caused by pollEvent().
« Reply #7 on: March 04, 2015, 03:20:13 pm »
Just start it again and try it? If you'd like to close it again, right click its icon in the system tray area (next to your taskbar clock) and pick the "Exit" option - or kill its process from within task manager.

Having it running while testing my application does not seem to have any significant effect now, which would point towards it being the reboot which solved it. It feels strange considering I'm fairly certain the problem has been consistent through multiple reboots in the past, but none of those previous reboots did however check for inconsistency in one of my harddrives. But it would seem my computer did indeed just need a good old reboot.