From 806fc7c3e5d84b38074e78e9d32c9fc31a5ebb42 Mon Sep 17 00:00:00 2001 From: /jedi/ Date: Thu, 8 Nov 2018 14:37:35 +0100 Subject: [PATCH] fix memory leak in layout.cpp --- Makefile | 6 +++++- linux.Makefile | 4 ++++ src/gfx/layout.cpp | 2 ++ src/hal/avr.cpp | 19 +++++++------------ src/main.cpp | 26 +++++++++++++------------- 5 files changed, 31 insertions(+), 26 deletions(-) diff --git a/Makefile b/Makefile index 6a32bbf..116ed2a 100644 --- a/Makefile +++ b/Makefile @@ -14,9 +14,13 @@ lib/libssd1306.a: @mkdir -p lib @cp deps/ssd1306/bld/libssd1306.a lib/libssd1306.a -flash: +flash: avr @make -f avr.Makefile flash +run: linux + @make -f linux.Makefile run + + clean: @rm -r build @echo clean all diff --git a/linux.Makefile b/linux.Makefile index 7f3236b..f6f1ca3 100644 --- a/linux.Makefile +++ b/linux.Makefile @@ -42,3 +42,7 @@ $(OBJDIR): clean: @$(REMOVEDIR) "$(OBJDIR)" @echo clean $(OBJDIR) + +run: $(OBJDIR)/$(TARGET) + @echo run $(OBJDIR)/$(TARGET) + @$(OBJDIR)/$(TARGET) diff --git a/src/gfx/layout.cpp b/src/gfx/layout.cpp index 01cd19c..7632851 100644 --- a/src/gfx/layout.cpp +++ b/src/gfx/layout.cpp @@ -46,6 +46,8 @@ int layout::expand_(int packedsize) { if (size > slots[i].content->maxsize) size = slots[i].content->maxsize; slots[i].size_ = size; + if(slots[i].canvas_) + delete slots[i].canvas_; slots[i].canvas_ = new canvas(size, maxheight_); pos += size; } diff --git a/src/hal/avr.cpp b/src/hal/avr.cpp index f560829..461f253 100644 --- a/src/hal/avr.cpp +++ b/src/hal/avr.cpp @@ -9,15 +9,11 @@ #include #include -uint8_t *canvasData; -NanoCanvas *canvas; +uint8_t canvasData[128 * (32 / 8)]; +NanoCanvas canvas(128, 32, canvasData); void hal_init_screen(int w, int h) { ssd1306_128x32_i2c_init(); - ssd1306_fillScreen( 0x00 ); - canvasData = new uint8_t[w * (h / 8)]; - canvas = new NanoCanvas(w, h, canvasData); - canvas.clear(); DDRD = 0; PORTD |= (1 << PC2) | (1 << PC3) | (1 << PC4) | (1 << PC5); @@ -31,17 +27,16 @@ void hal_draw(int x, int y){ void hal_poll_input(bool *ptr) { int in = PIND & 0x3c; - ptr[0] = in & (1 << PC2); - ptr[1] = in & (1 << PC3); - ptr[2] = in & (1 << PC4); - ptr[3] = in & (1 << PC5); + ptr[0] = !(in & (1 << PC2)); + ptr[1] = !(in & (1 << PC3)); + ptr[2] = !(in & (1 << PC4)); + ptr[3] = !(in & (1 << PC5)); } void hal_render() { - while (true) { - canvas.clear(); + ssd1306_fillScreen( 0x00 ); render(); canvas.blt(0, 0); } diff --git a/src/main.cpp b/src/main.cpp index 348b6e6..a415d41 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -31,19 +31,17 @@ int main() { root = new menu("", new menu("foo", - new menu("bar", - new menu("baz", - new fooValue("I", 5), - new fooValue("II", 5), - new fooValue("III", 5), - new fooValue("IIII", 5) - ), - new menu("peng", - new fooValue("o", 5), - new fooValue("oo", 5), - new fooValue("o o", 5) - ) - ), + new menu("baz", + new fooValue("I", 5), + new fooValue("II", 5), + new fooValue("III", 5), + new fooValue("IIII", 5) + ), + new menu("peng", + new fooValue("o", 5), + new fooValue("oo", 5), + new fooValue("o o", 5) + ), new menu("x", new fooValue("x x", 5), new fooValue("xxx", 5) @@ -93,6 +91,8 @@ void buttons::onPush(int id, bool state) { l.cursor = c; } break; + case I_UP: + break; case I_RIGHT: c = l.cursor; if (c = c->getCursor()) {