# Stuttering

This topic is 3884 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hello all. I have been working on a game program for a few weeks, and I just noticed that it seems to stutter ever so slightly every second or so. It is an almost imperceptible amount that doesn't even really register on the FRAPS FPS counter. My early test versions didn't do so, although they were simply a camera moving around inside a skybox. My map isn't very complex, <30k polygons and a 1024x1024 texture stretched across them. I'm going back over my code again and again and I'm having trouble finding out what might be causing this. What are the best and most reliable methods of investigating a problem such as this? Perhaps there is a good feature in visual studio's debugging that lets you watch code execution, or something like that?

##### Share on other sites
sounds like it might be related to the size of your video memory. how much do you have? If not all of the textures you are using fit in the VRAM, then the computer has to shuffle them back and forth from the video card as needed, producing noticeable hiccups.

##### Share on other sites
My video card has 512 MB of memory. Would this memory issue perhaps cause me to be getting errors when I attempt to load a heightmap larger than 128x128 (if I attempt to pass the entire index buffer as one whole)?

I'm not sure the problem is the texture - I'm actually using the same texture I was using in my early stages, and I had no issues then. However, when I loaded a map that was 64 x 64 I was still getting noticeable slowdown. I suppose I can try breaking the index buffer into two smaller ones, but is there a more immediate way to determine my issue before I go changing things?

##### Share on other sites
Quote:
 Original post by ultimastrikeI have been working on a game program for a few weeks, and I just noticed that it seems to stutter ever so slightly every second or so. It is an almost imperceptible amount that doesn't even really register

I've had similar problems in the past that were caused by faulty timer code - the timer would occasionally report that a frame was shorter/longer that it actually was, causing me to pass a slightly incorrect delta value into my update functions, causing a slight stutter from time to time...

How are you controlling the timing values in your game (i.e. the time values used for movement of the camera, etc.)?

##### Share on other sites
Profiling can get nasty. Hiccups are worse. Best thing to do is to drop in profiling calls inside your main loop. Then, section it off to a particular function call. This may take a few iterative passes to locate the issue. Here are a few things to check for starters. The 2-4Mb texture on the skydome is prolly the issue if you aren't using mip maps(it can cache thrash pretty randomly).

CPU issues:
Frequently File I/O calls
Networking code(this usually varies a lot frame to frame)
Too many batches(usually not hiccups)

GPU issues:
Usually fill limited issues.
Frequently cache thrashing
Big Textures without mip maps in the distance.
Nasty pixel shaders esp. with dynamic branching

In any event, you have a question to ask yourself. Is this something that is a bug that needs to be addressed right now or would it be better addressed after you finish your project(in an optimization pass)? If now is the time, (I'd opt for game logic instead ) then you need to select some sort of profiling tool or roll your own. You need to be able to tell aggregately how much time a code block is taking each fram so that you can section off your app's code and you will see where the problem really lies.

##### Share on other sites
I had a problem a while ago where roughly every second I'd get a slight hiccup, where it would apparently drop a frame and then give me a double timedelta (Which made objects fly off and generally behave unpleasantly).

After a while, I found that I could get rid of the problem by switching from Debug Direct3D to Release. I'm not too sure if this was the cause of the problem, but it certainly seemed to fix it. :)

##### Share on other sites
Lots of good replies. I'll answer them in order.

@Hodgeman: I'm using the following code as my timer:

static int time, start_time = GetTickCount();
time = GetTickCount() - start_time;
start_time = GetTickCount();

// for every millisecond...
for(int ms = 0; ms < time; ms++)

....

// handle movement
if(InputData->MoveDown && movetime < 0)
{
//Move something
movetime = 150;
}

That's the timer given by directxtutorial.com. It seems to work very well, I can't really find anything wrong with it.

@yoshscout:

You really sound like you know what you're doing. Luckily, few if any of those points apply to my project. It isn't multi-threaded yet, I only read input from a heightmap one time on initialization, there is no networking, and what is a batch? I don't use any fancy pixel shading stuff yet. The texture stretched across my landscape however is 16 MB, and the six skydome textures are around 20 KB each. These textures did not cause any slowdown previously when my landscape was a simple flat square, but now I get slowdown no matter what size landscape I load. So I'm a little confused. Anyway, I'd really like to get this done now because it's actually pretty annoying despite being invisible to FRAPS.

@PlayfulPuppy: That's a good idea, and one of the first things I tried was release configuration. Unfortunately it produced exactly the same results. Too bad the fix couldn't have been something that easy.

So when I get off of work tonight I'll try loading a simple texture and see if that speeds things up. If not, I'm going to have to find a profiling tool as yoshscout is suggesting. Can anyone suggest a reliable one?

##### Share on other sites
I have had a similar problem once. It was caused by slightly faulty camera class code. I was updating the my direction vector after I was updating the view matrix from it.

This stuttering/shakiness was more pronounced the farther fromt the origin the camera was. If your stuttering is not dependant on location, then you may have some other issue.

Maybe you can post your camera code.

##### Share on other sites
Another possibility would be swapping. Even if your application does not take that much memory (say, 50%), the combined memory usage of all "active" tasks on your system may be close to your physical RAM.

Last time I experienced that kind of problem, it was due to a background task taking up too much resources (on Linux).

In your code, is it really "ms++", or is it "ms += delta", with delta>1 ?
In the latter case, that could also explain it. Personally, I use something like that:

static int last_update;int now;...now = getTime();while (last_update + delta < now){  // Update  ...  last_update += delta;}

##### Share on other sites
The code I posted above was copied and pasted from my project, although I took out stuff that wasn't related to timing. So I'm pretty sure that what you suggested isn't the problem, johdex, although thank you muchly for your input :D

1. 1
2. 2
3. 3
Rutin
18
4. 4
JoeJ
14
5. 5

• 14
• 9
• 23
• 9
• 32
• ### Forum Statistics

• Total Topics
632625
• Total Posts
3007508
• ### Who's Online (See full list)

There are no registered users currently online

×