diff --git a/launch_miyoo.sh b/launch_miyoo.sh index a04b246..c533d5a 100644 --- a/launch_miyoo.sh +++ b/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 diff --git a/main.cpp b/main.cpp index 82540ec..796b417 100644 --- a/main.cpp +++ b/main.cpp @@ -1,4 +1,5 @@ #include +#include #include #include #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;