Browse Source

Add signal crash handler and support automatic log backup

main
Matteo Benedetto 1 month ago
parent
commit
5950434cd3
  1. 6
      launch_miyoo.sh
  2. 28
      main.cpp

6
launch_miyoo.sh

@ -2,6 +2,12 @@
# Launcher CyberMatris per Miyoo Mini Plus (OnionOS / Stock OS)
GAMEDIR=$(dirname "$0")
LOGFILE="$GAMEDIR/cybermatris.log"
# Preserva il log della sessione precedente (utile in caso di crash improvvisi)
if [ -f "$LOGFILE" ]; then
mv "$LOGFILE" "$GAMEDIR/cybermatris.old.log"
fi
exec > "$LOGFILE" 2>&1
set -x

28
main.cpp

@ -1,4 +1,5 @@
#include <SDL2/SDL.h>
#include <csignal>
#include <iostream>
#include <chrono>
#ifdef MIYOO_BUILD
@ -12,7 +13,34 @@
#include "Synth.hpp"
#include "Renderer.hpp"
// Crash signal handler to print diagnostic trace to cybermatris.log
void crashHandler(int signum) {
std::cerr << "\n\n==================================================" << std::endl;
std::cerr << "[CRASH DETECTED] CyberMatris caught fatal signal " << signum;
switch (signum) {
case SIGSEGV: std::cerr << " (SIGSEGV: Segmentation Fault)"; break;
case SIGABRT: std::cerr << " (SIGABRT: Abort / Assertion failed)"; break;
case SIGFPE: std::cerr << " (SIGFPE: Floating Point Exception)"; break;
case SIGILL: std::cerr << " (SIGILL: Illegal Instruction)"; break;
case SIGBUS: std::cerr << " (SIGBUS: Bus Error)"; break;
default: std::cerr << " (Unknown Signal)"; break;
}
std::cerr << "\n==================================================" << std::endl;
std::cerr.flush();
// Restore default handler and re-raise to complete execution termination
std::signal(signum, SIG_DFL);
std::raise(signum);
}
int main([[maybe_unused]] int argc, [[maybe_unused]] char* argv[]) {
// Register crash signal handlers
std::signal(SIGSEGV, crashHandler);
std::signal(SIGABRT, crashHandler);
std::signal(SIGFPE, crashHandler);
std::signal(SIGILL, crashHandler);
std::signal(SIGBUS, crashHandler);
// 1. Initialize SDL2 subsystems
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0) {
std::cerr << "SDL could not initialize! SDL_Error: " << SDL_GetError() << std::endl;

Loading…
Cancel
Save