From 2b7033b685bea40de956fdbe92341181ff85c219 Mon Sep 17 00:00:00 2001 From: Fabian Schlenz Date: Fri, 4 Oct 2019 12:03:03 +0200 Subject: [PATCH] cycle effect now tracks the heap leakage of the running effects. Cause somewhere's a memory leak leading to restarts of the ESP every about 2 days... --- include/effect_cycle.h | 1 + src/effect_cycle.cpp | 16 +++++++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/include/effect_cycle.h b/include/effect_cycle.h index 2cd685f..c745422 100644 --- a/include/effect_cycle.h +++ b/include/effect_cycle.h @@ -8,6 +8,7 @@ private: Effect* effect = NULL; uint16_t effect_id = -1; unsigned long effectSince = 0; + uint16_t _heap_free = 0; uint8_t _effects_count; public: CycleEffect(); diff --git a/src/effect_cycle.cpp b/src/effect_cycle.cpp index a26a21e..8a36804 100644 --- a/src/effect_cycle.cpp +++ b/src/effect_cycle.cpp @@ -29,16 +29,26 @@ void CycleEffect::changeEffect() { if (effect) delete effect; + int16_t diff; + uint16_t old_heap = _heap_free; + _heap_free = ESP.getFreeHeap(); + if (old_heap) { + // diff positive = More heap used (baad) + // diff negative = Less heap used (good-ish) + diff = old_heap - _heap_free; + LOGln("CycleEffect * Heap usage: #%d,%d,%+d", effect_id, _heap_free, diff); + } + delay(25); LOGln("CycleEffect * Searching for new effect #%d", new_id); + uint8_t count = 0; for (uint8_t i=0; i