Open jayseeee opened 12 years ago
Already reported this bug on google code but it did not get fixed yet.
Have you verified that the destructor gets called? I seem to remember that the current implementation of delete does not call destructors? Let me know and I'll fix this problem if the destructors actually gets called. (Either way I think I'll fix this, just because it's good practice.) PS: Maybe I'm confusing this with virtual destructors?
Dear Alexander, I verified that the destructor gets called! Delete always calls the destructor. Can be a problem when using derived classes and pointers to this derived classes in which case you have to define a virtual destructor as explained in: http://www.programmerinterview.com/index.php/c-cplusplus/virtual-destructors/
With the new tool chain I think we're ready to support virtual destructors, as a note to self: Remember to define int cxa_guard_acquire(guard g) {return !(char _)(g);}; void cxa_guard_release (guard g) {_(char )g = 1;}; void cxa_guard_abort (guard *) {}; void __cxa_pure_virtual(void) {};
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