ref: 96ff3f7bc127889c9f47e4ec17faa445ade623f1
parent: ea90460a261fb602af273041f3b226f2b723ebd2
author: Simon Howard <[email protected]>
date: Wed Apr 30 17:33:43 EDT 2014
system: Refactor error dialog box. When showing error message via Zenity, show the expanded (sprintf'ed) error, not the format string. Refactor the sprintf part to be part of the common code to avoid duplication.
--- a/src/i_system.c
+++ b/src/i_system.c
@@ -356,6 +356,7 @@
void I_Error (char *error, ...)
{
+ char msgbuf[512];
va_list argptr;
atexit_listentry_t *entry;
boolean exit_gui_popup;
@@ -369,7 +370,7 @@
{
already_quitting = true;
}
-
+
// Message first.
va_start(argptr, error);
//fprintf(stderr, "\nError: ");
@@ -378,6 +379,12 @@
va_end(argptr);
fflush(stderr);
+ // Write a copy of the message into buffer.
+ va_start(argptr, error);
+ memset(msgbuf, 0, sizeof(msgbuf));
+ M_vsnprintf(msgbuf, sizeof(msgbuf), error, argptr);
+ va_end(argptr);
+
// Shutdown. Here might be other errors.
entry = exit_funcs;
@@ -394,19 +401,14 @@
exit_gui_popup = !M_ParmExists("-nogui");
+ // Pop up a GUI dialog box to show the error message, if the
+ // game was not run from the console (and the user will
+ // therefore be unable to otherwise see the message).
+ if (exit_gui_popup && !I_ConsoleStdout())
#ifdef _WIN32
- // On Windows, pop up a dialog box with the error message.
-
- if (exit_gui_popup)
{
- char msgbuf[512];
wchar_t wmsgbuf[512];
- va_start(argptr, error);
- memset(msgbuf, 0, sizeof(msgbuf));
- M_vsnprintf(msgbuf, sizeof(msgbuf), error, argptr);
- va_end(argptr);
-
MultiByteToWideChar(CP_ACP, 0,
msgbuf, strlen(msgbuf) + 1,
wmsgbuf, sizeof(wmsgbuf));
@@ -414,17 +416,10 @@
MessageBoxW(NULL, wmsgbuf, L"", MB_OK);
}
#elif defined(__MACOSX__)
- if (exit_gui_popup && !I_ConsoleStdout())
{
CFStringRef message;
- char msgbuf[512];
int i;
- va_start(argptr, error);
- memset(msgbuf, 0, sizeof(msgbuf));
- M_vsnprintf(msgbuf, sizeof(msgbuf), error, argptr);
- va_end(argptr);
-
// The CoreFoundation message box wraps text lines, so replace
// newline characters with spaces so that multiline messages
// are continuous.
@@ -450,9 +445,8 @@
NULL);
}
#else
- if (exit_gui_popup && !I_ConsoleStdout())
{
- ZenityErrorBox(error);
+ ZenityErrorBox(msgbuf);
}
#endif