Files
Crosspoint/src/activities/home/CrashActivity.cpp
T
Xuan-Son Nguyen 243ae8b408 feat: show crash reason on boot (#1453)
## Summary

If the system reboots from crash, display the reason and tell user to
include `crash_report.txt` file.

To test this, simply add an `assert(false)` somewhere inside the code.


![screenshot-74453.bmp](https://github.com/user-attachments/files/26160373/screenshot-74453.bmp)

---

### AI Usage

While CrossPoint doesn't have restrictions on AI tools in contributing,
please be transparent about their usage as it
helps set the right context for reviewers.

Did you use AI tools to help write this code? **NO**
2026-04-13 15:23:45 -05:00

62 lines
1.8 KiB
C++

#include "CrashActivity.h"
#include <GfxRenderer.h>
#include <HalSystem.h>
#include <I18n.h>
#include "components/UITheme.h"
#include "fontIds.h"
void CrashActivity::onEnter() {
Activity::onEnter();
panicMessage = HalSystem::getPanicInfo(false);
if (panicMessage.empty()) {
panicMessage = tr(STR_CRASH_NO_REASON);
}
HalSystem::clearPanic();
requestUpdateAndWait();
}
void CrashActivity::loop() {
if (mappedInput.isPressed(MappedInputManager::Button::Back)) {
finish();
}
}
void CrashActivity::render(RenderLock&&) {
renderer.clearScreen();
const auto& metrics = UITheme::getInstance().getMetrics();
const auto pageWidth = renderer.getScreenWidth();
const auto contentWidth = pageWidth - 2 * metrics.contentSidePadding;
const auto x = metrics.contentSidePadding;
const auto lineHeight = renderer.getLineHeight(UI_10_FONT_ID);
GUI.drawHeader(renderer, Rect{0, metrics.topPadding, pageWidth, metrics.headerHeight}, tr(STR_CRASH_TITLE));
int y = metrics.topPadding + metrics.headerHeight + metrics.verticalSpacing;
auto descLines = renderer.wrappedText(UI_10_FONT_ID, tr(STR_CRASH_DESCRIPTION), contentWidth, 10);
for (const auto& line : descLines) {
renderer.drawText(UI_10_FONT_ID, x, y, line.c_str());
y += lineHeight;
}
y += metrics.verticalSpacing * 2;
renderer.drawText(UI_10_FONT_ID, x, y, tr(STR_CRASH_REASON));
y += lineHeight + metrics.verticalSpacing;
auto panicLines = renderer.wrappedText(UI_10_FONT_ID, panicMessage.c_str(), contentWidth, 5);
for (const auto& line : panicLines) {
renderer.drawText(UI_10_FONT_ID, x, y, line.c_str());
y += lineHeight;
}
const auto labels = mappedInput.mapLabels(tr(STR_BACK), "", "", "");
GUI.drawButtonHints(renderer, labels.btn1, labels.btn2, labels.btn3, labels.btn4);
renderer.displayBuffer();
}