Report errors using SDL message box

This commit is contained in:
kichikuou
2019-12-27 19:41:55 +09:00
parent 874f6bae5b
commit 6e73c48e68
6 changed files with 41 additions and 26 deletions
+1 -2
View File
@@ -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);
}
// カーソル初期化
+15 -10
View File
@@ -4,6 +4,7 @@
[ NACT ]
*/
#include <stdarg.h>
#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;
}
+2
View File
@@ -256,6 +256,8 @@ public:
void output_console(char log[]);
int get_scenario_page() const { return scenario_page; }
void fatal(const char* msg, ...);
};
#endif
+8 -5
View File
@@ -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;
}
+8 -5
View File
@@ -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;
}
+7 -4
View File
@@ -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;
}