summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSimon Howard2014-04-30 21:33:43 -0400
committerSimon Howard2014-04-30 21:33:43 -0400
commit96ff3f7bc127889c9f47e4ec17faa445ade623f1 (patch)
tree2818c684336584b4bbd1357be688e08684df1ec2 /src
parentea90460a261fb602af273041f3b226f2b723ebd2 (diff)
downloadchocolate-doom-96ff3f7bc127889c9f47e4ec17faa445ade623f1.tar.gz
chocolate-doom-96ff3f7bc127889c9f47e4ec17faa445ade623f1.tar.bz2
chocolate-doom-96ff3f7bc127889c9f47e4ec17faa445ade623f1.zip
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.
Diffstat (limited to 'src')
-rw-r--r--src/i_system.c32
1 files changed, 13 insertions, 19 deletions
diff --git a/src/i_system.c b/src/i_system.c
index 5aa57348..4e076d9d 100644
--- a/src/i_system.c
+++ b/src/i_system.c
@@ -356,6 +356,7 @@ static boolean already_quitting = false;
void I_Error (char *error, ...)
{
+ char msgbuf[512];
va_list argptr;
atexit_listentry_t *entry;
boolean exit_gui_popup;
@@ -369,7 +370,7 @@ void I_Error (char *error, ...)
{
already_quitting = true;
}
-
+
// Message first.
va_start(argptr, error);
//fprintf(stderr, "\nError: ");
@@ -378,6 +379,12 @@ void I_Error (char *error, ...)
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 @@ void I_Error (char *error, ...)
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 @@ void I_Error (char *error, ...)
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 @@ void I_Error (char *error, ...)
NULL);
}
#else
- if (exit_gui_popup && !I_ConsoleStdout())
{
- ZenityErrorBox(error);
+ ZenityErrorBox(msgbuf);
}
#endif