From 2450451a53d0a3650ce859de27855c8ece5279b9 Mon Sep 17 00:00:00 2001 From: Pete Favelle Date: Mon, 12 Sep 2022 13:45:39 +0100 Subject: [PATCH 1/3] Initialise newly allocated buffer_t data to zero, to clear up display corruption --- libraries/utility.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/utility.cpp b/libraries/utility.cpp index 7a9848a..b951f4d 100644 --- a/libraries/utility.cpp +++ b/libraries/utility.cpp @@ -60,7 +60,7 @@ namespace picosystem { buffer_t *b = new buffer_t(); b->w = w; b->h = h; - b->data = data ? (color_t *)data : new color_t[w * h]; + b->data = data ? (color_t *)data : new color_t[w * h]{}; return b; } @@ -111,4 +111,4 @@ namespace picosystem { return _fsin_lut[uint8_t((v * _2PI_LUTS) + 64)]; } -} \ No newline at end of file +} From edeea558c6f36fe80dd092a738fd691dd452986a Mon Sep 17 00:00:00 2001 From: Pete Favelle Date: Mon, 12 Sep 2022 14:08:26 +0100 Subject: [PATCH 2/3] Track when we allocate data in buffer_t, and delete it in destructor --- libraries/picosystem.hpp | 5 +++++ libraries/utility.cpp | 11 ++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/libraries/picosystem.hpp b/libraries/picosystem.hpp index edbc1cd..c0cbf05 100644 --- a/libraries/picosystem.hpp +++ b/libraries/picosystem.hpp @@ -34,10 +34,15 @@ namespace picosystem { struct buffer_t { int32_t w, h; color_t *data; + bool alloc; color_t *p(int32_t x, int32_t y) { return data + (x + y * w); } + + ~buffer_t() { + if (alloc) delete data; + } }; struct voice_t { diff --git a/libraries/utility.cpp b/libraries/utility.cpp index b951f4d..aa17092 100644 --- a/libraries/utility.cpp +++ b/libraries/utility.cpp @@ -60,7 +60,16 @@ namespace picosystem { buffer_t *b = new buffer_t(); b->w = w; b->h = h; - b->data = data ? (color_t *)data : new color_t[w * h]{}; + if (data) + { + b->data = (color_t *)data; + b->alloc = false; + } + else + { + b->data = new color_t[w * h]{}; + b->alloc = true; + } return b; } From eb7e4cc024b9fe8d1b16800450cf5d85a9f46eb6 Mon Sep 17 00:00:00 2001 From: Pete Favelle Date: Mon, 12 Sep 2022 14:14:13 +0100 Subject: [PATCH 3/3] Python lint fixes, from @Gadgetoid --- micropython/examples/picosystem/text.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/micropython/examples/picosystem/text.py b/micropython/examples/picosystem/text.py index 8f09c0b..24a1623 100644 --- a/micropython/examples/picosystem/text.py +++ b/micropython/examples/picosystem/text.py @@ -10,10 +10,10 @@ def update(tick): global view - if(pressed(RIGHT)): + if pressed(RIGHT): view += 1 - if(pressed(LEFT)): + if pressed(LEFT): view -= 1 view %= view_count