Skip to content

Destructor in Sprite Library missing #17

@jayseeee

Description

@jayseeee

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

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions