Sign in to follow this  

C++ SFML Stuttering

Recommended Posts

I've been having this issue with SFML where every half a second or so, my game would stutter (as in, a slight lag spike).

 

I've tried running old projects and the issue persisted.

 

After researching this issue a bit, it seems as though it's not necessarily my fault - however, I've tried updating drivers and doing other things that were recommended to people who were having my problem, but nothing worked.

 

Have any of you had this issue with SFML before? If so, did you solve it? How? Thanks for all replies.

Share this post


Link to post
Share on other sites

Do you have f.lux installed? (An application that automatically adjusts the screen color depending on time of day).

 

I remember a user on this forum having an issue with stuttering because of it, so it might be worth checking.

 

If that isn't the case, I would try outputting some debug data to see whether frame times inside update or draw vary a lot.

Share this post


Link to post
Share on other sites

Do you have f.lux installed? (An application that automatically adjusts the screen color depending on time of day).

 

I remember a user on this forum having an issue with stuttering because of it, so it might be worth checking.

 

If that isn't the case, I would try outputting some debug data to see whether frame times inside update or draw vary a lot.

I don't have f.lux installed, or anything else that affects screen brightness (as far as I'm concerned).

 

After outputting debug data like you said, I can verify that the frame times vary a lot. It can dip from 3000 to ~700 (more or less).

Share this post


Link to post
Share on other sites
In what way do you observe the stuttering? Are you updating your game in fixed time steps or variable time steps? If you’re updating in variable time steps, then read up on Gaffer’s “Fix Your Timestep”. If you aren’t, then read it anyway.

That aside, be careful when measuring in frames per second, as it not linear. 3000 fps to 700 fps seems like a significant drop, but in reality, you went from 0.33 ms to 1.43 ms in frame time, out of a total of 16.67 ms (for 60 fps). From 2.0% to 8.6% your total 60 fps budget.

Seems like you still have some wiggle room. :^)

Share this post


Link to post
Share on other sites

In what way do you observe the stuttering? Are you updating your game in fixed time steps or variable time steps? If you’re updating in variable time steps read, then up on Gaffer’s “Fix Your Timestep”. If you aren’t, then read it anyway.

That aside, be careful when measuring in frames per second, as it not linear. 3000 fps to 700 fps seems like a significant drop, but in reality, you went from 0.33 ms to 1.43 ms in frame time, out of a total of 16.67 ms (for 60 fps). From 2.0% to 8.6% your total 60 fps budget.

Seems like you still have some wiggle room. :^)

Yeah, that makes sense. When I framelocked it to 60 fps, it would drop down to ~19.

 

The stutters are pretty clear in-game. It would be a lag spike that lasts for about half a second, and it happens at half a second intervals.

 

This has affected every SFML project I've had as far as I can tell.

 

I'll just do a bit more research. Thanks anyways!

 

EDIT: The issue got fixed, but I'm not entirely sure how.

Edited by Debz

Share this post


Link to post
Share on other sites

For half a second, huh? Then the issue is probably elsewhere. What does your memory management look like? Are you making frequent allocations or deallocations? What about asset loading? Are you loading all of your assets each frame? Or at load time?

Yeah, the issue got fixed somehow. Thanks anyways!

 

Just to answer your question, I load my assets at load time.

Share this post


Link to post
Share on other sites
If you can measure your frame times (as it seems like you can) you should be able to narrow down the part of the code that is taking longer than expected to execute. Try to profile certain parts of the frame, and see if that gives you any hints.

I recently had a stuttering issue in windowed mode which seemed to be fixed by turning on vsync. Do you use that?

Share this post


Link to post
Share on other sites

What's your hardware rendering config like? Do you have v-sync enabled?

 

Have you tried profiling your code to find out what exactly is stalling out for hundreds of ms at a time? This involves adding timing code into your project where you can instantiate a timer object and then call a function to 'start' timing and 'stop' timing for that object, much like a stopwatch. EDIT: you would then create these timers for different pieces of your main update loop code, so as to differentiate what parts of your code are spending more/less time each frame. At the end of a session you would then output the total execution time for all of the timing objects you instantiated. This should help you narrow down what part of your code is stalling. Are you (assuming C/C++) compiling in debug or release mode? What other software do you have running in the background? Have you restarted your computer recently? (some people just sleep/awake their computer for months at a time, and it slows stuff down as memory fragments worse and worse)

 

I'd suggest running your project on another machine besides the one you are having problems on, to see if it's your project specifically or your machine itself. However, I think profiling your code will help you figure it out better than anything else.

Edited by deftware

Share this post


Link to post
Share on other sites

The problem seems to have come back.

Then you should know what you changed this time?
Try to roll back recent changes and measure, compare the differences. You are using version control software, right?

PS: You might get better answers on SFML forum, as people there know more about the library.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this