Hello,
I just found out that there is a bug in the sprite library, as the memory allocated for the storage of a sprite (i.e. _buffer) never gets deallocated. The destructor of a sprite is missing.
I had to add the following code to Sprite.cpp:
===================================================
#include <string.h>
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;
}
===================================================
And consequently the following lines in Sprite.h:
===================================================
Sprite(const Sprite &other);
~Sprite();
Sprite& operator=(const Sprite &other);
===================================================
I hope this helps other people playing around with the Sprite library and run into strange hangings of the program caused by the lack of free SRAM.
Perhaps this addition finds its way into a further release of the Arduino software.
Kind regards,
Jean-Claude