From 4fbc532dc4fe667e4570aad8b3e8c2a8ff0882e3 Mon Sep 17 00:00:00 2001 From: saurav Date: Sun, 15 Dec 2024 22:49:14 +0530 Subject: [PATCH] Fixed issues causing ESP to restart --- Drawable.cpp | 24 ++++++++---------------- Fragment.cpp | 4 +++- Fragments.h | 2 +- SSD1306.cpp | 1 + 4 files changed, 13 insertions(+), 18 deletions(-) diff --git a/Drawable.cpp b/Drawable.cpp index ea76943..466d36d 100644 --- a/Drawable.cpp +++ b/Drawable.cpp @@ -20,8 +20,7 @@ const char *Circle::type() const Circle::~Circle() { - if (this != nullptr) - delete this; + // delete this; } Rectangle::Rectangle(uint8_t x, uint8_t y, uint8_t width, uint8_t height, uint8_t cornerRadius, uint8_t thickness) @@ -39,8 +38,7 @@ const char *Rectangle::type() const Rectangle::~Rectangle() { - if (this != nullptr) - delete this; + // delete this; } Line::Line(uint8_t startX, uint8_t startY, uint8_t endX, uint8_t endY, uint8_t thickness) @@ -58,8 +56,7 @@ const char *Line::type() const Line::~Line() { - if (this != nullptr) - delete this; + // delete this; } Bitmap::Bitmap(const uint8_t *dataSet, uint8_t x, uint8_t y, uint8_t width, uint8_t height) @@ -77,8 +74,7 @@ const char *Bitmap::type() const Bitmap::~Bitmap() { - if (this != nullptr) - delete this; + // delete this; } Text::Text(String text, uint8_t x, uint8_t y) @@ -96,8 +92,7 @@ const char *Text::type() const Text::~Text() { - if (this != nullptr) - delete this; + // delete this; } HighlightedText::HighlightedText(String text, uint8_t x, uint8_t y) @@ -115,8 +110,7 @@ const char *HighlightedText::type() const HighlightedText::~HighlightedText() { - if (this != nullptr) - delete this; + // delete this; } AnimatedText::AnimatedText(String text, uint8_t x, uint8_t y, int delay, bool highlight) @@ -134,8 +128,7 @@ const char *AnimatedText::type() const AnimatedText::~AnimatedText() { - if (this != nullptr) - delete this; + // delete this; } GridView::GridView(Drawable *drawable, uint8_t count, uint8_t countPerLine, uint8_t startX, uint8_t startY, uint8_t seperationX, uint8_t seperationY) @@ -239,6 +232,5 @@ const char *GridView::type() const GridView::~GridView() { - if (this != nullptr) - delete this; + // delete this; } \ No newline at end of file diff --git a/Fragment.cpp b/Fragment.cpp index ab37653..4e88e1b 100644 --- a/Fragment.cpp +++ b/Fragment.cpp @@ -36,8 +36,10 @@ void Fragment::add(Drawable *drawable) for (int i = 0; i < drawableCount; ++i) { newDrawables[i] = drawables[i]; + yield(); } - delete[] drawables; + if (drawables != nullptr) + delete[] drawables; drawables = newDrawables; } drawables[drawableCount++] = drawable; diff --git a/Fragments.h b/Fragments.h index c750be4..543a295 100644 --- a/Fragments.h +++ b/Fragments.h @@ -219,7 +219,7 @@ class Fragment { private: FragmentManager &manager; - Drawable **drawables; + Drawable **drawables = nullptr; uint8_t drawableCount; uint8_t drawableCapacity; uint8_t lastCount = 0; diff --git a/SSD1306.cpp b/SSD1306.cpp index b0a536e..f3bc16d 100644 --- a/SSD1306.cpp +++ b/SSD1306.cpp @@ -949,6 +949,7 @@ void OLED::circle(uint8_t centerX, uint8_t centerY, uint8_t radius, uint8_t thic drawPixel(centerX - y, centerY + x); drawPixel(centerX + y, centerY - x); drawPixel(centerX - y, centerY - x); + yield(); } radius--; }