- rewrote all remaining places that used wm_msgbox to throw a fatal error instead so that the global error handler can deal with the messages.

This eliminates another piece of hideous code.
This commit also moves the memory error handler to the common code, so that all games can call it if triggered.
This commit is contained in:
Christoph Oelckers 2019-12-24 19:59:14 +01:00
parent f65b2c1dcb
commit 055b310d60
8 changed files with 20 additions and 136 deletions

View file

@ -56,9 +56,6 @@ void mouseGrabInput(bool grab);
void getScreen(uint8_t* imgBuf);
int32_t wm_msgbox(const char *name, const char *fmt, ...) ATTRIBUTE((format(printf,2,3)));
int32_t wm_ynbox(const char *name, const char *fmt, ...) ATTRIBUTE((format(printf,2,3)));
#include "print.h"
struct GameStats

View file

@ -151,52 +151,6 @@ void I_FatalError(const char* error, ...)
}
int32_t wm_msgbox(const char *name, const char *fmt, ...)
{
char buf[2048];
va_list va;
UNREFERENCED_PARAMETER(name);
va_start(va,fmt);
vsnprintf(buf,sizeof(buf),fmt,va);
va_end(va);
#if defined EDUKE32_OSX
return osx_msgbox(name, buf);
#elif defined _WIN32
MessageBoxA(nullptr,buf,name,MB_OK|MB_TASKMODAL);
return 0;
#elif defined EDUKE32_TOUCH_DEVICES
initprintf("wm_msgbox called. Message: %s: %s",name,buf);
return 0;
#elif defined GEKKO
puts(buf);
return 0;
#else
# if defined HAVE_GTK2
if (gtkbuild_msgbox(name, buf) >= 0)
return 0;
# endif
# if SDL_MAJOR_VERSION > 1
# if !defined _WIN32
// Replace all tab chars with spaces because the hand-rolled SDL message
// box diplays the former as N/L instead of whitespace.
for (size_t i=0; i<sizeof(buf); i++)
if (buf[i] == '\t')
buf[i] = ' ';
# endif
return SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_INFORMATION, name, buf, NULL);
# else
puts(buf);
puts(" (press Return or Enter to continue)");
getchar();
return 0;
# endif
#endif
}
void videoResetMode(void)

View file

@ -292,6 +292,8 @@ int RunGame();
int GameMain()
{
set_memerr_handler(G_HandleMemErr);
int r;
try
{
@ -583,13 +585,25 @@ int RunGame()
if (enginePreInit())
{
I_Error("app_main: There was a problem initializing the Build engine: %s\n", engineerrstr);
I_FatalError("app_main: There was a problem initializing the Build engine: %s\n", engineerrstr);
}
mouseGrabInput(true); // the intros require the mouse to be grabbed.
return gi->app_main();
}
void G_HandleMemErr(int32_t lineNum, const char* fileName, const char* funcName)
{
I_FatalError("Out of memory in %s:%d (%s)\n", fileName, lineNum, funcName);
}
void G_FatalEngineError(void)
{
I_FatalError("Fatal Engine Initialization Error",
"There was a problem initializing the engine: %s\n\nThe application will now close.", engineerrstr);
}
//==========================================================================
//
//

View file

@ -149,3 +149,6 @@ const char* G_ConFile(void);
TArray<GrpEntry> GrpScan();
void S_SetSoundPaused(int state);
void G_HandleMemErr(int32_t lineNum, const char* fileName, const char* funcName);
void G_FatalEngineError(void);

View file

@ -5505,23 +5505,10 @@ void G_PostCreateGameState(void)
A_InitEnemyFlags();
}
static void G_HandleMemErr(int32_t lineNum, const char *fileName, const char *funcName)
{
I_FatalError("Out of memory in %s:%d (%s)\n", fileName, lineNum, funcName);
}
static void G_FatalEngineError(void)
{
I_FatalError("Fatal Engine Initialization Error",
"There was a problem initializing the engine: %s\n\nThe application will now close.", engineerrstr);
}
static void G_Startup(void)
{
int32_t i;
set_memerr_handler(&G_HandleMemErr);
timerInit(TICRATE);
timerSetCallback(gameTimerHandler);

View file

@ -6947,31 +6947,10 @@ void G_PostCreateGameState(void)
A_InitEnemyFlags();
}
static void G_HandleMemErr(int32_t lineNum, const char *fileName, const char *funcName)
{
static char msg[128];
Bsnprintf(msg, sizeof(msg), "Out of memory in %s:%d (%s)\n", fileName, lineNum, funcName);
#ifdef DEBUGGINGAIDS
Bassert(0);
#endif
G_GameExit(msg);
}
static void G_FatalEngineError(void)
{
wm_msgbox("Build Engine Initialization Error",
"There was a problem initializing the Build engine: %s", engineerrstr);
G_Cleanup();
ERRprintf("G_Startup: There was a problem initializing the Build engine: %s\n", engineerrstr);
exit(6);
}
static void G_Startup(void)
{
int32_t i;
set_memerr_handler(&G_HandleMemErr);
timerInit(TICRATE);
timerSetCallback(gameTimerHandler);

View file

@ -703,19 +703,8 @@ void MultiSharewareCheck(void)
if (!SW_SHAREWARE) return;
if (numplayers > 4)
{
#if 1 /* defined RENDERTYPEWIN */
wm_msgbox(apptitle,"To play a Network game with more than 4 players you must purchase "
I_FatalError("To play a Network game with more than 4 players you must purchase "
"the full version. Read the Ordering Info screens for details.");
#else
printf(
"\n\nTo play a Network game with more than 4 players you must purchase the\n"
"full version. Read the Ordering Info screens for details.\n\n");
#endif
//uninitmultiplayers();
//uninitkeys();
engineUnInit();
timerUninit();
Bexit(0);
}
}
@ -2500,48 +2489,10 @@ void Control()
void _Assert(const char *expr, const char *strFile, unsigned uLine)
{
buildprintf(ds, "Assertion failed: %s %s, line %u", expr, strFile, uLine);
debug_break();
TerminateGame();
#if 1 /* defined RENDERTYPEWIN */
wm_msgbox(apptitle, "%s", ds);
#else
printf("Assertion failed: %s\n %s, line %u\n", expr, strFile, uLine);
#endif
exit(0);
I_FatalError("Assertion failed: %s %s, line %u", expr, strFile, uLine);
}
void _ErrMsg(const char *strFile, unsigned uLine, const char *format, ...)
{
va_list arglist;
//DSPRINTF(ds, "Error: %s, line %u", strFile, uLine);
//MONO_PRINT(ds);
TerminateGame();
#if 1 /* defined RENDERTYPEWIN */
{
char msg[256], *p;
Bsnprintf(msg, sizeof(msg), "Error: %s, line %u\n", strFile, uLine);
p = &msg[strlen(msg)];
va_start(arglist, format);
Bvsnprintf(msg, sizeof(msg) - (p-msg), format, arglist);
va_end(arglist);
wm_msgbox(apptitle, "%s", msg);
}
#else
printf("Error: %s, line %u\n", strFile, uLine);
va_start(arglist, format);
vprintf(format, arglist);
va_end(arglist);
#endif
exit(0);
}
void dsprintf(char *str, const char *format, ...)
{

View file

@ -33,7 +33,6 @@ Prepared for public release: 03/28/2005 - Charlie Wiederhold, 3D Realms
BEGIN_SW_NS
void _ErrMsg(const char *strFile, unsigned uLine, const char *format, ...);
void FAF_DrawRooms(int posx, int posy, int posz, short ang, int horiz, short cursectnum);
////////////////////////////////////////////////////////////////////