-
Notifications
You must be signed in to change notification settings - Fork 165
Open
Description
The destructor is missing in the sprite library (and also in the matrix library) which leads to a memory leak when dynamically creating sprites. When adding a destructor it becomes necessary to add a copy and an assignment operator.
The following addtions should be made to the sprite library:
Sprite::Sprite(const Sprite &other)
{
operator=(other); // Call the assignment operator
}
Sprite::~Sprite()
{
if (!_buffer) return;
free(_buffer); // Make sure to free the buffer if it exists
}
Sprite& Sprite::operator=(const Sprite &other)
{
_width = other._width;
_height = other._height;
init(_width, _height);
memcpy(_buffer,other._buffer,_height);
return *this;
}
Kind regards,
Jean-Claude
Metadata
Metadata
Assignees
Labels
No labels