From 4de46eb5a7645e7058bb09e1ff9b3f1e7be54b49 Mon Sep 17 00:00:00 2001 From: Holger Schemel Date: Wed, 20 Nov 2013 00:54:55 +0100 Subject: [PATCH] rnd-20131120-1-src * improved error handling: display error message on screen (not only in the error file or on the console), and display path of the error file --- ChangeLog | 4 ++++ src/Makefile | 6 ++--- src/conftime.h | 2 +- src/init.c | 53 ++++++++++++++++++++++++++++++++++++++++++++ src/init.h | 2 ++ src/libgame/misc.c | 7 ++++++ src/libgame/system.c | 5 +++++ src/libgame/system.h | 2 ++ src/libgame/text.c | 18 +++++++++++++++ src/libgame/text.h | 2 ++ src/main.c | 1 + 11 files changed, 98 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 7a07f579..65c1b093 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2013-11-20 + * improved error handling: display error message on screen (not only in + the error file or on the console), and display path of the error file + 2013-11-13 * fixed problem with R'n'D restarting with same level set that may have caused a problem (and therefore failing again and again); after an diff --git a/src/Makefile b/src/Makefile index 854d6e2f..b8c53054 100644 --- a/src/Makefile +++ b/src/Makefile @@ -327,13 +327,13 @@ clean: clean-obj clean-ico clean-bin # run and test targets # ----------------------------------------------------------------------------- -run: all +run: cd .. && ./$(PROGBASE) --verbose -gdb: all +gdb: cd .. && gdb -batch -x GDB_COMMANDS ./$(PROGBASE) -valgrind: all +valgrind: cd .. && valgrind -v --leak-check=yes ./$(PROGBASE) 2> valgrind.out diff --git a/src/conftime.h b/src/conftime.h index 92f1b94c..04d6ca99 100644 --- a/src/conftime.h +++ b/src/conftime.h @@ -1 +1 @@ -#define COMPILE_DATE_STRING "2013-11-13 01:14" +#define COMPILE_DATE_STRING "2013-11-20 00:53" diff --git a/src/init.c b/src/init.c index 4735f046..b1e9920e 100644 --- a/src/init.c +++ b/src/init.c @@ -6274,6 +6274,59 @@ void KeyboardAutoRepeatOffUnlessAutoplay() KeyboardAutoRepeatOff(); } +void DisplayExitMessage(char *format, va_list ap) +{ + int font_1 = FC_RED; + int font_2 = FC_YELLOW; + int font_3 = FC_BLUE; + int font_width = getFontWidth(font_2); + int font_height = getFontHeight(font_2); + int sx = SX; + int sy = SY; + int sxsize = WIN_XSIZE - 2 * sx; + int sysize = WIN_YSIZE - 2 * sy; + int line_length = sxsize / font_width; + int max_lines = sysize / font_height; + int num_lines_printed; + + gfx.sx = sx; + gfx.sy = sy; + gfx.sxsize = sxsize; + gfx.sysize = sysize; + + sy = 20; + + ClearRectangle(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE); + + DrawTextSCentered(sy, font_1, "Fatal error:"); + sy += 3 * font_height;; + + num_lines_printed = + DrawTextBufferVA(sx, sy, format, ap, font_2, + line_length, line_length, max_lines, + 0, BLIT_ON_BACKGROUND, TRUE, TRUE, FALSE); + sy += (num_lines_printed + 3) * font_height; + + DrawTextSCentered(sy, font_1, "For details, see the following error file:"); + sy += 3 * font_height; + + num_lines_printed = + DrawTextBuffer(sx, sy, program.error_filename, font_2, + line_length, line_length, max_lines, + 0, BLIT_ON_BACKGROUND, TRUE, TRUE, FALSE); + + DrawTextSCentered(SYSIZE - 20, font_3, "Press any key or button to exit"); + + redraw_mask = REDRAW_ALL; + + BackToFront(); + + /* deactivate toons on error message screen */ + setup.toons = FALSE; + + WaitForEventToContinue(); +} + /* ========================================================================= */ /* OpenAll() */ diff --git a/src/init.h b/src/init.h index 42bc9f74..d52aef4d 100644 --- a/src/init.h +++ b/src/init.h @@ -46,6 +46,8 @@ void KeyboardAutoRepeatOffUnlessAutoplay(); void InitGfxBuffers(); void InitGadgets(); +void DisplayExitMessage(char *, va_list); + void OpenAll(void); void CloseAllAndExit(int); diff --git a/src/libgame/misc.c b/src/libgame/misc.c index 7e273ada..b70545be 100644 --- a/src/libgame/misc.c +++ b/src/libgame/misc.c @@ -1045,6 +1045,13 @@ void Error(int mode, char *format, ...) va_start(ap, format); vfprintf_newline(program.error_file, format, ap); va_end(ap); + + if ((mode & ERR_EXIT) && !(mode & ERR_FROM_SERVER)) + { + va_start(ap, format); + program.exit_message_function(format, ap); + va_end(ap); + } } if (mode & ERR_HELP) diff --git a/src/libgame/system.c b/src/libgame/system.c index da379735..6d99c7c8 100644 --- a/src/libgame/system.c +++ b/src/libgame/system.c @@ -105,6 +105,11 @@ void InitProgramInfo(char *argv0, program.error_file = stderr; } +void InitExitMessageFunction(void (*exit_message_function)(char *, va_list)) +{ + program.exit_message_function = exit_message_function; +} + void InitExitFunction(void (*exit_function)(int)) { program.exit_function = exit_function; diff --git a/src/libgame/system.h b/src/libgame/system.h index b6c2ad3b..5c197691 100644 --- a/src/libgame/system.h +++ b/src/libgame/system.h @@ -679,6 +679,7 @@ struct ProgramInfo int version_minor; int version_patch; + void (*exit_message_function)(char *, va_list); void (*exit_function)(int); }; @@ -1230,6 +1231,7 @@ extern int FrameCounter; void InitProgramInfo(char *, char *, char *, char *, char *, char *, char *, char *, char *, char *, char *, char *, int); +void InitExitMessageFunction(void (*exit_message_function)(char *, va_list)); void InitExitFunction(void (*exit_function)(int)); void InitPlatformDependentStuff(void); void ClosePlatformDependentStuff(void); diff --git a/src/libgame/text.c b/src/libgame/text.c index 9d4d1193..dd926f62 100644 --- a/src/libgame/text.c +++ b/src/libgame/text.c @@ -947,6 +947,24 @@ int DrawTextBuffer(int x, int y, char *text_buffer, int font_nr, return current_line; } +int DrawTextBufferVA(int x, int y, char *format, va_list ap, int font_nr, + int line_length, int cut_length, int max_lines, + int line_spacing, int mask_mode, boolean autowrap, + boolean centered, boolean parse_comments) +{ + char text_buffer[MAX_OUTPUT_LINESIZE]; + int text_length = vsnprintf(text_buffer, MAX_OUTPUT_LINESIZE, format, ap); + + if (text_length >= MAX_OUTPUT_LINESIZE) + Error(ERR_WARN, "string too long in DrawTextBufferVA() -- truncated"); + + int num_lines_printed = DrawTextBuffer(x, y, text_buffer, font_nr, + line_length, cut_length, max_lines, + line_spacing, mask_mode, autowrap, + centered, parse_comments); + return num_lines_printed; +} + int DrawTextFile(int x, int y, char *filename, int font_nr, int line_length, int cut_length, int max_lines, int line_spacing, int mask_mode, boolean autowrap, diff --git a/src/libgame/text.h b/src/libgame/text.h index 1d54a716..17d350a0 100644 --- a/src/libgame/text.h +++ b/src/libgame/text.h @@ -91,6 +91,8 @@ void DrawTextExt(DrawBuffer *, int, int, char *, int, int); char *GetTextBufferFromFile(char *, int); int DrawTextBuffer(int, int, char *, int, int, int, int, int, int, boolean, boolean, boolean); +int DrawTextBufferVA(int, int, char *, va_list, int, int, int, int, int, int, + boolean, boolean, boolean); int DrawTextFile(int, int, char *, int, int, int, int, int, int, boolean, boolean, boolean); diff --git a/src/main.c b/src/main.c index 94c5c3ac..aaa3a5ba 100644 --- a/src/main.c +++ b/src/main.c @@ -5594,6 +5594,7 @@ int main(int argc, char *argv[]) MSDOS_POINTER_FILENAME, COOKIE_PREFIX, FILENAME_PREFIX, GAME_VERSION_ACTUAL); + InitExitMessageFunction(DisplayExitMessage); InitExitFunction(CloseAllAndExit); InitPlatformDependentStuff(); -- 2.34.1