3
\$\begingroup\$

As stated in the title, my program stutters like crazy, even though my program for the most part runs for 60 fps. During the moments it stutters, FPS momentarily drops down to 59(stats from FRAPS).

Here is an video capture of the stuttering in action. If you look closely, you can see the game stutter around 3-4 times. It is much more noticeable in real life.

http://gfycat.com/SevereCanineBabirusa

CLR Profiler shows that garbage collection doesn't run at all during that time, never mind 4 times, so it's not that.

Here's the code for movement:

            //Movement logic
            //Increase the speed
            speed = Math.Min(speed + (speedIncrement * (gameTime.ElapsedGameTime.Milliseconds / 200.0f)), maxSpeed);

            for (int i = fruits.Count - 1; i >= 0; i--)
            {
                //Move the fruits
                fruits[i].pos.Y += speed * gameTime.ElapsedGameTime.Milliseconds;
                fruits[i].rect.Y = (int)fruits[i].pos.Y;
                //Check if the fruit is past the screen. If it is, remove it from fruits
                if (fruits[i].rect.Y > screenHeight)
                {
                    fruits.Remove(fruits[i]);
                }
            }

IsFixedTimeStep is set to false, but SyncronizeWithVerticalTrace is on. Any idea what could be the cause of the stuttering?

EDIT: Apparently it was a combination of this: http://answers.microsoft.com/en-us/windows/forum/windows_7-performance/presentationfontcacheexe-uses-50-of-my-cpu/4200fe85-458f-4f19-b791-1fe5395304da and f.lux eating up my CPU/GPU cycles.

\$\endgroup\$
4
  • \$\begingroup\$ What is your platform? Sounds like the XBox GC being called too often. \$\endgroup\$ – ClassicThunder Jun 23 '14 at 18:44
  • \$\begingroup\$ Just the PC. Again, according to the CLR Profiler, the GC is usually not called or called only once during that. \$\endgroup\$ – guest0294203 Jun 23 '14 at 19:51
  • \$\begingroup\$ xboxforums.create.msdn.com/forums/t/9934.aspx?PageIndex=2 \$\endgroup\$ – ClassicThunder Jun 25 '14 at 18:31
  • \$\begingroup\$ I'm actually guessing you read the above before since you are using a fixed time step and ElapsedGameTime at the same time, or atleast something that tackled the same issues. Mainly posting it is the most complete discussion of the issue I have seen. \$\endgroup\$ – ClassicThunder Jun 25 '14 at 18:36
1
\$\begingroup\$

Try using Stopwatch to capture a start and end time at the beginning and end of your Update method to find an average time spent in Update. Then, add a branch to a breakpoint when the time exceeds the average by some threshold and take a look at the program state at that time.

You might consider recycling your objects by moving them to a pool, instead of simply forgetting about them altogether. While it probably isn't the GC interrupting the flow, it worth checking out.

Also, try building the game in Release mode instead of Debug, if you haven't done so already.

\$\endgroup\$
5
  • \$\begingroup\$ I used stopwatch to time the loops, and stopwatch reports that the Update method takes 0 or 1 millisecond. There was no large outlier. CLR Profiler reports that GC rarely runs, so it probably isn't that. Also, could you expand what you mean by building in Release mode? Do you mean publishing it and running that .exe? \$\endgroup\$ – guest0294203 Jun 24 '14 at 19:26
  • \$\begingroup\$ Take a look at msdn.microsoft.com/en-us/library/wx0123s5(v=vs.100).aspx \$\endgroup\$ – jzx Jun 24 '14 at 21:15
  • 1
    \$\begingroup\$ For some reason, there seems to be no option to set Release of Debug in the Build tab.I suppose it's because I'm running using Monogame, and not vanilla XNA. \$\endgroup\$ – guest0294203 Jun 24 '14 at 22:04
  • 2
    \$\begingroup\$ Furthermore, I've just tried running the simple game that Microsoft provides as a tutorial here: msdn.microsoft.com/en-us/library/bb203893.aspx. When I increase the speed, the stuttering happens here as well, which leads me to think that it's not a problem with my code, but rather that of my hardware or XNA itself. \$\endgroup\$ – guest0294203 Jun 24 '14 at 22:09
  • \$\begingroup\$ Sorry to bother you again, but I've make a (semi) breakthrough. It seems that every time the game stutters, the time between Draw calls is usually about ~32ms, whereas it is usually ~16ms. However, I then commented out all of the other logic in the Update and Draw methods, and these large gaps between draw calls still happen. Is this just a case of other processes taking up my GPU and CPU time? \$\endgroup\$ – guest0294203 Jun 25 '14 at 1:58
0
\$\begingroup\$

Set IsFixedTimestep = false. But in doing so, you'll need to consider Shawn Hargreaves' explanation first: http://xboxforums.create.msdn.com/forums/p/9934/53561.aspx#53561.

\$\endgroup\$
2
  • \$\begingroup\$ OP has already stated they have set IsFixedTimestep = false. Good link though. \$\endgroup\$ – Seta Jun 23 '14 at 18:39
  • \$\begingroup\$ Yeah, it's already set to false, and I've accounted for it through using gameTime. \$\endgroup\$ – guest0294203 Jun 23 '14 at 18:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.