From ef088db789c6a3bf105ff2e4274b54e3c9bbef4b Mon Sep 17 00:00:00 2001 From: jpirnay Date: Fri, 17 Apr 2026 19:09:16 +0200 Subject: [PATCH] Add more logging --- src/activities/Activity.h | 1 + src/activities/ActivityManager.cpp | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/src/activities/Activity.h b/src/activities/Activity.h index cc3fe443..f74599a2 100644 --- a/src/activities/Activity.h +++ b/src/activities/Activity.h @@ -27,6 +27,7 @@ class Activity { explicit Activity(std::string name, GfxRenderer& renderer, MappedInputManager& mappedInput) : name(std::move(name)), renderer(renderer), mappedInput(mappedInput) {} virtual ~Activity() = default; + const std::string& getName() const { return name; } virtual void onEnter(); virtual void onExit(); virtual void loop() {} diff --git a/src/activities/ActivityManager.cpp b/src/activities/ActivityManager.cpp index d1c0da40..86acbeb1 100644 --- a/src/activities/ActivityManager.cpp +++ b/src/activities/ActivityManager.cpp @@ -3,6 +3,9 @@ #include #include #include +#include +#include +#include #include "CrossPointState.h" #include "boot_sleep/BootActivity.h" @@ -29,6 +32,17 @@ void ActivityManager::begin() { assert(renderTaskHandle != nullptr && "Failed to create render task"); } +static void logActivityStackState(const char* stage, Activity* currentActivity, size_t stackSize) { + const uint32_t freeHeap = esp_get_free_heap_size(); + const uint32_t contigHeap = heap_caps_get_largest_free_block(MALLOC_CAP_8BIT | MALLOC_CAP_DEFAULT); + LOG_DBG("ACT", "%s: current=%s stackSize=%zu free=%lu contig=%lu", + stage, + currentActivity ? currentActivity->getName().c_str() : "", + stackSize, + freeHeap, + contigHeap); +} + void ActivityManager::renderTaskTrampoline(void* param) { auto* self = static_cast(param); self->renderTaskLoop(); @@ -149,6 +163,7 @@ void ActivityManager::loop() { RenderLock lock; if (pendingAction == PendingAction::Replace) { + logActivityStackState("replace_before", currentActivity.get(), stackActivities.size()); // Destroy the current activity exitActivity(lock); // Clear the stack @@ -156,10 +171,13 @@ void ActivityManager::loop() { stackActivities.back()->onExit(); stackActivities.pop_back(); } + logActivityStackState("replace_after_clear", nullptr, stackActivities.size()); } else if (pendingAction == PendingAction::Push) { + logActivityStackState("push_before", currentActivity.get(), stackActivities.size()); // Move current activity to stack stackActivities.push_back(std::move(currentActivity)); LOG_DBG("ACT", "Pushed to activity stack, new size = %zu", stackActivities.size()); + logActivityStackState("push_after", currentActivity.get(), stackActivities.size()); } pendingAction = PendingAction::None; currentActivity = std::move(pendingActivity); @@ -201,6 +219,8 @@ void ActivityManager::replaceActivity(std::unique_ptr&& newActivity) { if (currentActivity) { // Defer launch if we're currently in an activity, to avoid deleting the current activity // leading to the "delete this" problem + LOG_DBG("ACT", "replaceActivity requested: current=%s stackSize=%zu", + currentActivity->getName().c_str(), stackActivities.size()); pendingActivity = std::move(newActivity); pendingAction = PendingAction::Replace; } else { @@ -274,6 +294,8 @@ void ActivityManager::pushActivity(std::unique_ptr&& activity) { LOG_ERR("ACT", "pendingActivity while pushActivity is not expected"); pendingActivity.reset(); } + LOG_DBG("ACT", "pushActivity requested: current=%s stackSize=%zu", + currentActivity ? currentActivity->getName().c_str() : "", stackActivities.size()); pendingActivity = std::move(activity); pendingAction = PendingAction::Push; }