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

Author Topic: Weird stuttering issue  (Read 1591 times)

0 Members and 1 Guest are viewing this topic.

iride

  • Jr. Member
  • **
  • Posts: 88
    • View Profile
    • Email
Weird stuttering issue
« on: February 12, 2017, 08:47:02 am »
Hello, I have a strange stuttering issue with this code.
#include "Core/MathUtility.h"
#include <SFML/Graphics.hpp>
int main()
{
        sf::RenderWindow window(sf::VideoMode(1000, 800), "SFML works!");
        sf::CircleShape shape(100.f);
        shape.setFillColor(sf::Color::Green);
       
        sf::Clock clock;
        sf::Time elapsed = sf::Time::Zero;
        sf::Vector2f pos;
        sf::Vector2f oldPos;


        while (window.isOpen())
        {
                elapsed += clock.restart();
                sf::Event event;
                while (window.pollEvent(event))
                {
                        if (event.type == sf::Event::Closed)
                                window.close();
                }
               
                while (elapsed >= sf::seconds(1 / 60.f))
                {
                        std::cout << "tick\n";
                        elapsed -= sf::seconds(1 / 60.f);
                        oldPos = pos;
                        if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
                                pos.x -= 5.f;
                        if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
                                pos.x += 5.f;
                }
                float t = elapsed.asSeconds() / sf::seconds(1 / 60.f).asSeconds();
                window.clear();
                sf::Vector2f renderPos = lerp(oldPos, pos, t);
                std::cout << "renderPos: " << renderPos.x << "\n";
                shape.setPosition(pos);
                window.draw(shape);
                window.display();
        }
        return 0;
}
 

I think the stutter comes from random high frametimes.
dt: 0.000104
renderPos: 298.681
dt: 0.038244
tick
tick
tick
renderPos: 310.154
dt: 0.000183
renderPos: 310.209
dt: 0.000158
renderPos: 310.257
dt: 0.037992
tick
tick
renderPos: 321.655
dt: 0.000206
renderPos: 321.716
dt: 0.000212
renderPos: 321.78

I'm using sfml 2.4.0, windows 10, i7 6700k/gtx 1070.
Sometimes if I reboot my computer, the stutter goes away.


What I don't understand is that stutter never seems to occur on my laptop with integrated graphics.

Exilef

  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: Weird stuttering issue
« Reply #1 on: February 12, 2017, 12:42:46 pm »
Hello. I think it might be the Windows Nvidia driver doing something weird when the program is "too fast". The same thing happens for me on Windows, but on Linux (same PC, same code) it's gone. I had the same problem before and it magically disappeared when the program had more to do in every frame. Now I finally know why.
I also found this thread: http://en.sfml-dev.org/forums/index.php?topic=16449.0. It's old, but I think it's the same problem. The solution for them was to turn off Threaded optimization.

 

anything