Update 85

I post update less often because for maybe an entire week I have only fixed bugs. I can now sum up all the interesting bugs.

One interesting bug I have is:
OpenGL makes a border around sprites in a sprite sheet when the sprite is rescaled.

And the things is, this artifact is not a bug but depends on which filter algorithm is used by OpenGL. There are multiple but the two without mipmapping are GL_NEAREST and GL_LINEAR. Using nearest-neighbor interpolation produce an ugly result, so I need to use a linear interpolation for the filter.

The problem with linear interpolation is it compute the value of a point with the adjacents points, and sometimes with a certain size, position and ratio a border of one pixel appear around the sprite. This is when the linear interpolation algorithm needs to take the color of a transparent point. When I generate the sprite sheet with openCV the transparent color used is black (RGBA) : (0, 0, 0, 0). So the line around the sprite will be darker than the rest of the sprite.

The solution to this problem is simple once everything is explained, make a border of one pixel around the sprites with the good colors. I can do that easily by reducing the size of the sprite by 2 pixels.

Another classic bug with vector is the invalidated iterator after addition (when a reallocation is needed) or the deletion of an item.

In my case, the objects in the vector were stored on the stack, and I was using the address of the item as a pointer. Everything is fine if the vector is not modified, but I am inserting and deleting things while using pointer => pointer are invalidated => accessing invalid space in memory => game crash. The solution is simply to allocate thing on the heap to obtain a pointer that does not point on the vector and continue to be valid after modifying the vector.

There are a lot of others small bugs but when testing now I am using this to check for heap corruption (for visual studio only):

Leave a Reply

Your email address will not be published. Required fields are marked *