Some memory leaks fixed.

This commit is contained in:
Fabian Schlenz 2019-06-19 22:23:49 +02:00
parent 9eeb4b50fd
commit 0163bbef6c
6 changed files with 18 additions and 6 deletions

View File

@ -10,6 +10,7 @@ private:
Window* window = new Window(0, LED_HEIGHT - 6, LED_WIDTH, 6);
public:
~ClockEffect();
void loop();
void loop(boolean invert, CRGB fg_color, CRGB bg_color);
};

View File

@ -17,6 +17,7 @@ private:
bool is_direction_okay(uint8_t direction);
public:
SnakeEffect();
~SnakeEffect();
void loop();
boolean valid_position(Coords c);
Coords update_position(Coords c, uint8_t direction);

View File

@ -40,3 +40,7 @@ void ClockEffect::loop(boolean invert, CRGB fg_color, CRGB bg_color) {
window->setPixel(7, 4, &fg_color);
}
}
ClockEffect::~ClockEffect() {
delete window;
}

View File

@ -3,7 +3,7 @@
GolEffect::GolEffect() {
this->window = new Window(0, 0, LED_WIDTH, LED_HEIGHT-6);
_data = new uint8_t[this->window->count];
_old = new uint8_t[this->window->count];
for(uint16_t i=0; i<this->window->count; i++) {
@ -26,6 +26,7 @@ void GolEffect::_initialize() {
GolEffect::~GolEffect() {
delete[] _data;
delete[] _old;
delete window;
}
void GolEffect::loop() {
@ -35,7 +36,7 @@ void GolEffect::loop() {
} else {
_blend += EFFECT_GOL_BLEND_SPEED;
}
_draw();
}
@ -52,14 +53,14 @@ void GolEffect::_advance() {
uint16_t changes = 0;
for(uint8_t x=0; x<this->window->width; x++) for(uint8_t y=0; y<this->window->height; y++) {
uint16_t index = y*w + x;
uint8_t count =
uint8_t count =
(x>0 && y>0 && _old[index - w - 1]) +
(y>0 && _old[index - w]) +
(x<this->window->width-1 && y>0 && _old[index - w + 1]) +
(x>0 && _old[index - 1]) +
(x<this->window->width-1 && _old[index + 1]) +
(x>0 && y<this->window->height-1 && _old[index + w - 1]) +
(y<this->window->height-1 && _old[index + w]) +
(x<this->window->width-1 && y<this->window->height-1 && _old[index + w + 1]);
@ -79,7 +80,7 @@ void GolEffect::_advance() {
}
}
}
if (changes == 0) {
_initialize();
}

View File

@ -10,6 +10,7 @@ PixelClockEffect::PixelClockEffect() {
PixelClockEffect::~PixelClockEffect() {
delete _color_seconds;
delete _color_minutes;
delete window;
}
void PixelClockEffect::loop() {

View File

@ -6,6 +6,10 @@ SnakeEffect::SnakeEffect() {
this->window = new Window(0, 0, LED_WIDTH, LED_HEIGHT-6);
}
SnakeEffect::~SnakeEffect() {
delete window;
}
void SnakeEffect::loop() {
if (run++ % EFFECT_SNAKE_SLOWDOWN == 0) { // Change the coordinates only on every n-th run.
if (random8(EFFECT_SNAKE_DIRECTION_CHANGE)==0 || is_turn_needed()) turn_random();