From 477edd1597c3c21a3fc39ae15933c4b7d95aa0bf Mon Sep 17 00:00:00 2001 From: Fabian Schlenz Date: Wed, 12 Jun 2019 06:30:26 +0200 Subject: [PATCH] I just learned that unintialized variables in C can lead to lots of unexpected and hard-to-debug behaviour... :-/ --- include/Animation.h | 6 +++--- src/Animation.cpp | 8 +++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/include/Animation.h b/include/Animation.h index 2329841..0374ca7 100644 --- a/include/Animation.h +++ b/include/Animation.h @@ -43,12 +43,12 @@ protected: uint8_t currentFrame = 0; uint8_t* animation_data; CRGB* colors; - CRGB* fgColor; + CRGB* fgColor = NULL; CRGB* bgColor = new CRGB(0x000000); int8_t xOffset = 0; int8_t yOffset = 0; - uint8_t startFrame; - uint8_t endFrame; + uint8_t startFrame = 0; + uint8_t endFrame = 0; virtual CRGB* getColor(uint8_t color_index); void drawFrame(Window* w, uint8_t frame_index); diff --git a/src/Animation.cpp b/src/Animation.cpp index 6328450..c5f4908 100644 --- a/src/Animation.cpp +++ b/src/Animation.cpp @@ -139,7 +139,9 @@ bool Animation::advance() { } void Animation::drawPixel(Window* win, int index, CRGB* color) { - win->setPixel(this->xOffset + (index % this->data->w), this->yOffset + (index / this->data->h), color); + uint8_t x = this->xOffset + (index % this->data->w); + uint8_t y = this->yOffset + (index / this->data->h); + win->setPixel(x, y, color); } uint16_t Animation::getFrameDelay(int frame) { @@ -149,6 +151,6 @@ uint16_t Animation::getFrameDelay(int frame) { CRGB* Animation::getColor(uint8_t index) { if (index==1) return this->bgColor; - else if (this->fgColor) return this->fgColor; - else return &this->colors[index - 2]; + else if (this->fgColor != NULL) return this->fgColor; + else return &(this->colors[index - 2]); }