From 6e73c48e68b750e0e9962cb2798a7efcbddc301b Mon Sep 17 00:00:00 2001 From: kichikuou Date: Fri, 27 Dec 2019 19:41:31 +0900 Subject: [PATCH] Report errors using SDL message box --- src/sys/ags.cpp | 3 +-- src/sys/nact.cpp | 25 +++++++++++++++---------- src/sys/nact.h | 2 ++ src/sys/nact_sys1.cpp | 13 ++++++++----- src/sys/nact_sys2.cpp | 13 ++++++++----- src/sys/nact_sys3.cpp | 11 +++++++---- 6 files changed, 41 insertions(+), 26 deletions(-) diff --git a/src/sys/ags.cpp b/src/sys/ags.cpp index 00d9311..23a3960 100644 --- a/src/sys/ags.cpp +++ b/src/sys/ags.cpp @@ -66,8 +66,7 @@ AGS::AGS(NACT* parent, const char* fontfile) : nact(parent) hFont48 = TTF_OpenFont(fontfile, 48); hFont64 = TTF_OpenFont(fontfile, 64); if (!hFont16 || !hFont24 || !hFont32 || !hFont48 || !hFont64) { - printf("Cannot open font file %s\n", fontfile); - exit(1); + parent->fatal("Cannot open font file %s", fontfile); } // カーソル初期化 diff --git a/src/sys/nact.cpp b/src/sys/nact.cpp index 08ca0c4..8ec4804 100644 --- a/src/sys/nact.cpp +++ b/src/sys/nact.cpp @@ -4,6 +4,7 @@ [ NACT ] */ +#include #include "nact.h" #include "ags.h" #include "mako.h" @@ -11,6 +12,8 @@ #include "../fileio.h" #include "crc32.h" +extern SDL_Window* g_window; + // 初期化 NACT::NACT(const char* fontfile) @@ -162,7 +165,7 @@ void NACT::execute() { // アドレスの確認 if(scenario_addr < 2 || scenario_addr >= scenario_size) { - fatal_error = true; + fatal("Scenario error"); } // 致命的なエラー発生 or 正常終了 @@ -370,14 +373,7 @@ void NACT::execute() output_console(string); #endif } else { - fatal_error = true; - -#if defined(_DEBUG_CONSOLE) - char log[128]; - memset(log, 0, sizeof(log)); - sprintf_s(log, 128, "\nFAILED: %2x, %d", cmd, scenario_addr); - output_console(log); -#endif + fatal("Unknown command %2x at %d", cmd, scenario_addr); } break; } @@ -390,7 +386,7 @@ void NACT::load_scenario(int page) } DRI* dri = new DRI(); if((scenario_data = dri->load(adisk, page + 1, &scenario_size)) == NULL) { - fatal_error = true; + fatal("Cannot load scenario %d", page); } delete dri; } @@ -439,3 +435,12 @@ void NACT::select_sound(int dev) mako->play_music(page); } } + +void NACT::fatal(const char* format, ...) { + char buf[512]; + va_list args; + va_start(args, format); + vsnprintf(buf, sizeof buf, format, args); + SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "system3", buf, g_window); + fatal_error = true; +} diff --git a/src/sys/nact.h b/src/sys/nact.h index e2c15c2..cf22e61 100644 --- a/src/sys/nact.h +++ b/src/sys/nact.h @@ -256,6 +256,8 @@ public: void output_console(char log[]); int get_scenario_page() const { return scenario_page; } + + void fatal(const char* msg, ...); }; #endif diff --git a/src/sys/nact_sys1.cpp b/src/sys/nact_sys1.cpp index aff3313..a87b820 100644 --- a/src/sys/nact_sys1.cpp +++ b/src/sys/nact_sys1.cpp @@ -191,7 +191,7 @@ void NACT::cmd_branch() // message (2 bytes) getd(); } else { - fatal_error = true; + fatal("cmd_branch: invalid command %2x", cmd); break; } } @@ -1499,7 +1499,7 @@ uint16 NACT::cali() { uint32 cali[256]; int p = 1; - fatal_error = true; + bool ok = false; while(p > 0) { uint8 dat = getd(); @@ -1546,11 +1546,14 @@ uint16 NACT::cali() p--; } else if(dat == 0x7f) { if(p == 2) { - fatal_error = false; + ok = true; } p = 0; } } + if (!ok) { + fatal("cali: invalid expression"); + } return (uint16)(cali[1] & 0xffff); } @@ -1564,10 +1567,10 @@ uint16 NACT::cali2() } else if(0xc0 <= dat && dat <= 0xff) { val = ((dat & 0x3f) << 8) | getd(); } else { - fatal_error = true; + fatal("cali2: invalid expression"); } if(getd() != 0x7f) { - fatal_error = true; + fatal("cali2: invalid expression"); } return val; } diff --git a/src/sys/nact_sys2.cpp b/src/sys/nact_sys2.cpp index e9e39df..9d4c0de 100644 --- a/src/sys/nact_sys2.cpp +++ b/src/sys/nact_sys2.cpp @@ -225,7 +225,7 @@ void NACT::cmd_branch() // message (2 bytes) getd(); } else { - fatal_error = true; + fatal("cmd_branch: invalid command %2x", cmd); break; } } @@ -1575,7 +1575,7 @@ uint16 NACT::cali() { uint32 cali[256]; int p = 1; - fatal_error = true; + bool ok = false; while(p > 0) { uint8 dat = getd(); @@ -1628,11 +1628,14 @@ uint16 NACT::cali() p--; } else if(dat == 0x7f) { if(p == 2) { - fatal_error = false; + ok = true; } p = 0; } } + if (!ok) { + fatal("cali: invalid expression"); + } return (uint16)(cali[1] & 0xffff); } @@ -1646,10 +1649,10 @@ uint16 NACT::cali2() } else if(0xc0 <= dat && dat <= 0xff) { val = ((dat & 0x3f) << 8) | getd(); } else { - fatal_error = true; + fatal("cali2: invalid expression"); } if(getd() != 0x7f) { - fatal_error = true; + fatal("cali2: invalid expression"); } return val; } diff --git a/src/sys/nact_sys3.cpp b/src/sys/nact_sys3.cpp index 708da8d..626e30c 100644 --- a/src/sys/nact_sys3.cpp +++ b/src/sys/nact_sys3.cpp @@ -1689,7 +1689,7 @@ uint16 NACT::cali() { uint32 cali[256]; int p = 1; - fatal_error = true; + bool ok = false; while(p > 0) { uint8 dat = getd(); @@ -1742,11 +1742,14 @@ uint16 NACT::cali() p--; } else if(dat == 0x7f) { if(p == 2) { - fatal_error = false; + ok = true; } p = 0; } } + if (!ok) { + fatal("cali: invalid expression"); + } return (uint16)(cali[1] & 0xffff); } @@ -1760,10 +1763,10 @@ uint16 NACT::cali2() } else if(0xc0 <= dat && dat <= 0xff) { val = ((dat & 0x3f) << 8) | getd(); } else { - fatal_error = true; + fatal("cali2: invalid expression"); } if(getd() != 0x7f) { - fatal_error = true; + fatal("cali2: invalid expression"); } return val; }