I am trying to create a simple game, but I cannot find a specific memory leak. Every second or so, the program seems to use 3 MB of memory.
The problem is with this drawing method. If I do not name this method, everything will be fine. I am trying to draw a sprite on several parts of the screen:
void Map::draw(HDC hBackBufferDC)
{
for(int i = 0; i < 24; i++)
{
for(int j = 0; j < 27; j++)
{
if(mapState[i][j] == 'm')
{
blueWall->draw(hBackBufferDC, new Position(j, i));
}
}
}
}
If I remove the draw method call, there is no problem, so the problem is this method:
void StaticSprite::draw(HDC hBackBufferDC, Position* pos)
{
int x = (int)pos->x * 22;
int y = (int)pos->y * 22;
HGDIOBJ oldObj = SelectObject(this->hSpriteDC, this->hMask);
BitBlt(hBackBufferDC, x, y, 22, 22, this->hSpriteDC, 0, 0, SRCAND);
SelectObject(this->hSpriteDC, this->hImage);
BitBlt(hBackBufferDC, x, y, 22, 22, this->hSpriteDC, 0, 0, SRCPAINT);
SelectObject(this->hSpriteDC, oldObj);
}
Any idea what causes a memory leak here? I think this is related to this part, but if necessary, I can place other parts of the code.
thank