Q: mp4 video of a simulation is being skewed horizontally I recently began programming a simulation for one of my high school classes. I have never worked in c++ before so I really should've done some practice programming first. Bear in mind this means my program is quite disorganized due to a rocky foundation. I have been trying to solve this error for almost two weeks now. So this post is my last resort. If I can't figure it out after this I will postpone it until I have more experience and just try to re-write it.
I have isolated the problem to a part of a method that blurs the image using a gaussian kernel. It iterates through all x and y values. For each pixel, it also iterates through dx and dy. (x + dx, y + dy) becomes the new coordinates where I read the value out of an image buffer, divide it by the correct amount, compound those 9 values from the kernel, then add that value to a new image buffer. I then replace all the values in the original buffer with the new ones.
And although the blur-ing works for the first frame:

By only the third frame, it is completely unrecognizable:

Eventually, the image settles from its noise-like state and looks something like this:

Brace yourself for the ugly code that is about to come...
void simulate(agent group[groupsize], int frames) {
    for (int framenumber = 0; framenumber < frames; framenumber++) {
        for (int agentIndex = 0; agentIndex < groupsize; agentIndex++)
        {
            group[agentIndex].update();
            int x = floor(group[agentIndex].xPos);
            int y = floor(group[agentIndex].yPos);
            imgBuffer = imgptr + getIndex(x,y);
            *imgBuffer = byteMax;
        }
        imgBuffer = imgptr;
        for (int y = 0; y < h; y++)
        {
            for (int x = 0; x < w; x++)
            {
                int index = 0;
                unsigned char val = byteZero;
                for (int dy = -1; dy <= 1; dy++)
                {
                    for (int dx = -1; dx <= 1; dx++)
                    {
                        index = getIndex(x + dx, y + dy);
                        if (0 < index && index < imgSize) {
                            imgBuffer = imgptr + index;
                            int shift = abs(dx) + abs(dy) + 2;
                            val += (*imgBuffer >> shift);
                        }
                    }
                }
                *tempBuffer = val;
                tempBuffer++;
            }

        }
        imgBuffer = imgptr;
        tempBuffer = tempptr;
        for (int i = 0; i < imgSize; i++)
        {
            *imgBuffer = *tempBuffer;
            if (*imgBuffer > fadeAmt) {
                *imgBuffer -= fadeAmt;
            }
            imgBuffer++;
            tempBuffer++;
        }
        imgBuffer = imgptr;
        tempBuffer = tempptr;
        writePPM(imgBuffer, w, h, framenumber);
    }
}

It comes down to the fact that I am inexperienced with c++. If you can help at all, whether that be gut reactions to the example frames or probable solutions, I would greatly appreciate it. I will be monitoring this post throughout the day(even though I should be paying attention in class LOL) so if you have any questions, I will answer them as fast as humanly possible.
I have tried more things than I can count. Almost all give slight variations to the examples above, yet never fully fix the issue.
