Fix crash when font not found

Now NACT::fatal() immediately exits the process.
This commit is contained in:
kichikuou
2024-04-06 08:31:37 +09:00
parent 2ae16c8c61
commit 723e5cef05
4 changed files with 16 additions and 17 deletions
+11 -13
View File
@@ -106,19 +106,17 @@ AGS::AGS(NACT* parent, const Config& config) : nact(parent), dirty(false)
if (!rw_font)
parent->fatal("Cannot open default font");
}
if (rw_font) {
hFont16 = TTF_OpenFontRW(rw_font, 0, 16);
SDL_RWseek(rw_font, 0, SEEK_SET);
hFont24 = TTF_OpenFontRW(rw_font, 0, 24);
SDL_RWseek(rw_font, 0, SEEK_SET);
hFont32 = TTF_OpenFontRW(rw_font, 0, 32);
SDL_RWseek(rw_font, 0, SEEK_SET);
hFont48 = TTF_OpenFontRW(rw_font, 0, 48);
SDL_RWseek(rw_font, 0, SEEK_SET);
hFont64 = TTF_OpenFontRW(rw_font, 0, 64);
if (!hFont16 || !hFont24 || !hFont32 || !hFont48 || !hFont64) {
parent->fatal("TTF_OpenFontRW failed: %s", TTF_GetError());
}
hFont16 = TTF_OpenFontRW(rw_font, 0, 16);
SDL_RWseek(rw_font, 0, SEEK_SET);
hFont24 = TTF_OpenFontRW(rw_font, 0, 24);
SDL_RWseek(rw_font, 0, SEEK_SET);
hFont32 = TTF_OpenFontRW(rw_font, 0, 32);
SDL_RWseek(rw_font, 0, SEEK_SET);
hFont48 = TTF_OpenFontRW(rw_font, 0, 48);
SDL_RWseek(rw_font, 0, SEEK_SET);
hFont64 = TTF_OpenFontRW(rw_font, 0, 64);
if (!hFont16 || !hFont24 || !hFont32 || !hFont48 || !hFont64) {
parent->fatal("TTF_OpenFontRW failed: %s", TTF_GetError());
}
if (config.no_antialias)
ags_setAntialiasedStringMode(0);
+3 -2
View File
@@ -5,6 +5,7 @@
*/
#include <stdarg.h>
#include <stdlib.h>
#include "nact.h"
#include "encoding.h"
#include "ags.h"
@@ -554,14 +555,14 @@ void NACT::select_cursor()
ags->select_cursor();
}
void NACT::fatal(const char* format, ...) {
[[noreturn]] void NACT::fatal(const char* format, ...) {
char buf[512];
va_list args;
va_start(args, format);
vsnprintf(buf, sizeof buf, format, args);
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Fatal Error: %s", buf);
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "system3", buf, g_window);
quit(0);
exit(1);
}
NACT* NACT::create(const Config& config) {
+1 -1
View File
@@ -287,7 +287,7 @@ public:
int get_scenario_page() const { return scenario_page; }
void fatal(const char* msg, ...);
[[noreturn]] void fatal(const char* msg, ...);
private:
void pump_events();
+1 -1
View File
@@ -262,7 +262,7 @@ void NACT_Sys2::cmd_branch()
} else if (cmd >= 0x20 && cmd < 0x7f) {
fatal("Unknown Command: '%c' at page = %d, addr = %d", cmd, scenario_page, prev_addr);
} else {
fatal("Unknown Command: %02x at page = %d, addr = %d", cmd, scenario_page, prev_addr);
fatal("Unknown Command: %02x at page = %d, addr = %d", cmd, scenario_page, prev_addr);
}
}
}