From 7bcc6aa833d64b21f78793dd00ed4c1356b98d05 Mon Sep 17 00:00:00 2001 From: Holger Schemel Date: Sat, 19 Sep 2020 00:18:07 +0200 Subject: [PATCH] changed fatal error handling to use new error functions --- src/editor.c | 28 +++++++-------- src/files.c | 9 +++-- src/game.c | 2 +- src/init.c | 28 +++++++-------- src/libgame/gadgets.c | 8 ++--- src/libgame/misc.c | 83 ++++++++++++++++++++++++++++++++++--------- src/libgame/misc.h | 2 ++ src/libgame/sdl.c | 26 ++++++-------- src/libgame/setup.c | 10 +++--- src/libgame/system.c | 6 ++-- src/libgame/text.c | 4 +-- src/netserv.c | 18 ++++------ src/network.c | 20 +++++------ src/screens.c | 8 ++--- src/tape.c | 8 ++--- src/tools.c | 4 +-- 16 files changed, 149 insertions(+), 115 deletions(-) diff --git a/src/editor.c b/src/editor.c index d8b25777..b7b739f5 100644 --- a/src/editor.c +++ b/src/editor.c @@ -6218,7 +6218,7 @@ static void CreateControlButtons(void) GDI_END); if (gi == NULL) - Error(ERR_EXIT, "cannot create gadget"); + Fail("cannot create gadget"); level_editor_gadget[id] = gi; } @@ -6284,7 +6284,7 @@ static void CreateControlButtons(void) GDI_END); if (gi == NULL) - Error(ERR_EXIT, "cannot create gadget"); + Fail("cannot create gadget"); level_editor_gadget[id] = gi; } @@ -6337,7 +6337,7 @@ static void CreateControlButtons(void) GDI_END); if (gi == NULL) - Error(ERR_EXIT, "cannot create gadget"); + Fail("cannot create gadget"); level_editor_gadget[id] = gi; } @@ -6431,7 +6431,7 @@ static void CreateCounterButtons(void) GDI_END); if (gi == NULL) - Error(ERR_EXIT, "cannot create gadget"); + Fail("cannot create gadget"); level_editor_gadget[id] = gi; right_gadget_border[id] = @@ -6493,7 +6493,7 @@ static void CreateCounterButtons(void) GDI_END); if (gi == NULL) - Error(ERR_EXIT, "cannot create gadget"); + Fail("cannot create gadget"); level_editor_gadget[id] = gi; right_gadget_border[id] = @@ -6551,7 +6551,7 @@ static void CreateDrawingAreas(void) GDI_END); if (gi == NULL) - Error(ERR_EXIT, "cannot create gadget"); + Fail("cannot create gadget"); level_editor_gadget[id] = gi; right_gadget_border[id] = @@ -6624,7 +6624,7 @@ static void CreateTextInputGadgets(void) GDI_END); if (gi == NULL) - Error(ERR_EXIT, "cannot create gadget"); + Fail("cannot create gadget"); level_editor_gadget[id] = gi; } @@ -6673,7 +6673,7 @@ static void CreateTextAreaGadgets(void) GDI_END); if (gi == NULL) - Error(ERR_EXIT, "cannot create gadget"); + Fail("cannot create gadget"); level_editor_gadget[id] = gi; } @@ -6752,7 +6752,7 @@ static void CreateSelectboxGadgets(void) GDI_END); if (gi == NULL) - Error(ERR_EXIT, "cannot create gadget"); + Fail("cannot create gadget"); level_editor_gadget[id] = gi; right_gadget_border[id] = @@ -6836,7 +6836,7 @@ static void CreateTextbuttonGadgets(void) GDI_END); if (gi == NULL) - Error(ERR_EXIT, "cannot create gadget"); + Fail("cannot create gadget"); level_editor_gadget[id] = gi; right_gadget_border[id] = @@ -6892,7 +6892,7 @@ static void CreateGraphicbuttonGadgets(void) GDI_END); if (gi == NULL) - Error(ERR_EXIT, "cannot create gadget"); + Fail("cannot create gadget"); level_editor_gadget[id] = gi; right_gadget_border[id] = @@ -7007,7 +7007,7 @@ static void CreateScrollbarGadgets(void) GDI_END); if (gi == NULL) - Error(ERR_EXIT, "cannot create gadget"); + Fail("cannot create gadget"); level_editor_gadget[id] = gi; } @@ -7067,7 +7067,7 @@ static void CreateCheckbuttonGadgets(void) GDI_END); if (gi == NULL) - Error(ERR_EXIT, "cannot create gadget"); + Fail("cannot create gadget"); level_editor_gadget[id] = gi; right_gadget_border[id] = @@ -7132,7 +7132,7 @@ static void CreateRadiobuttonGadgets(void) GDI_END); if (gi == NULL) - Error(ERR_EXIT, "cannot create gadget"); + Fail("cannot create gadget"); level_editor_gadget[id] = gi; right_gadget_border[id] = diff --git a/src/files.c b/src/files.c index 76aedc60..706b819e 100644 --- a/src/files.c +++ b/src/files.c @@ -11928,8 +11928,7 @@ void ConvertLevels(void) global.convert_leveldir); if (convert_leveldir == NULL) - Error(ERR_EXIT, "no such level identifier: '%s'", - global.convert_leveldir); + Fail("no such level identifier: '%s'", global.convert_leveldir); leveldir_current = convert_leveldir; @@ -12056,13 +12055,13 @@ void CreateLevelSketchImages(void) BlitBitmap(drawto, bitmap1, SX, SY, TILEX, TILEY, 0, 0); if (SDL_SaveBMP(bitmap1->surface, filename1) != 0) - Error(ERR_EXIT, "cannot save level sketch image file '%s'", filename1); + Fail("cannot save level sketch image file '%s'", filename1); DrawSizedElement(0, 0, element, MINI_TILESIZE); BlitBitmap(drawto, bitmap2, SX, SY, MINI_TILEX, MINI_TILEY, 0, 0); if (SDL_SaveBMP(bitmap2->surface, filename2) != 0) - Error(ERR_EXIT, "cannot save level sketch image file '%s'", filename2); + Fail("cannot save level sketch image file '%s'", filename2); free(filename1); free(filename2); @@ -12186,7 +12185,7 @@ void CreateCustomElementImages(char *directory) } if (SDL_SaveBMP(bitmap->surface, dst_filename) != 0) - Error(ERR_EXIT, "cannot save CE graphics file '%s'", dst_filename); + Fail("cannot save CE graphics file '%s'", dst_filename); FreeBitmap(bitmap); diff --git a/src/game.c b/src/game.c index ee3e9789..47fa48ad 100644 --- a/src/game.c +++ b/src/game.c @@ -15836,7 +15836,7 @@ void CreateGameButtons(void) GDI_END); if (gi == NULL) - Error(ERR_EXIT, "cannot create gadget"); + Fail("cannot create gadget"); game_gadget[id] = gi; } diff --git a/src/init.c b/src/init.c index 5c795f4c..44b0a5cb 100644 --- a/src/init.c +++ b/src/init.c @@ -1655,7 +1655,7 @@ static void set_cloned_graphic_parameters(int graphic) Warn("custom graphic rejected for this element/action"); if (graphic == fallback_graphic) - Error(ERR_EXIT, "no fallback graphic available"); + Fail("no fallback graphic available"); Warn("fallback done to 'char_exclam' for this graphic"); Warn("---"); @@ -1808,7 +1808,7 @@ static void InitGraphicInfo(void) Warn("custom graphic rejected for this element/action"); if (i == fallback_graphic) - Error(ERR_EXIT, "no fallback graphic available"); + Fail("no fallback graphic available"); Warn("fallback done to 'char_exclam' for this graphic"); Warn("---"); @@ -1839,7 +1839,7 @@ static void InitGraphicInfo(void) Warn("custom graphic rejected for this element/action"); if (i == fallback_graphic) - Error(ERR_EXIT, "no fallback graphic available"); + Fail("no fallback graphic available"); Warn("fallback done to 'char_exclam' for this graphic"); Warn("---"); @@ -4782,7 +4782,7 @@ static void InitGlobal(void) { // check if element_name_info entry defined for each element in "main.h" if (i < MAX_NUM_ELEMENTS && element_name_info[i].token_name == NULL) - Error(ERR_EXIT, "undefined 'element_name_info' entry for element %d", i); + Fail("undefined 'element_name_info' entry for element %d", i); element_info[i].token_name = element_name_info[i].token_name; element_info[i].class_name = element_name_info[i].class_name; @@ -4794,7 +4794,7 @@ static void InitGlobal(void) // check if global_anim_name_info defined for each entry in "main.h" if (i < NUM_GLOBAL_ANIM_TOKENS && global_anim_name_info[i].token_name == NULL) - Error(ERR_EXIT, "undefined 'global_anim_name_info' entry for anim %d", i); + Fail("undefined 'global_anim_name_info' entry for anim %d", i); global_anim_info[i].token_name = global_anim_name_info[i].token_name; } @@ -5011,7 +5011,7 @@ static void Execute_Command(char *command) char *filename = &command[11]; if (!fileExists(filename)) - Error(ERR_EXIT, "cannot open file '%s'", filename); + Fail("cannot open file '%s'", filename); LoadLevelFromFilename(&level, filename); DumpLevel(&level); @@ -5023,7 +5023,7 @@ static void Execute_Command(char *command) char *filename = &command[10]; if (!fileExists(filename)) - Error(ERR_EXIT, "cannot open file '%s'", filename); + Fail("cannot open file '%s'", filename); LoadTapeFromFilename(filename); DumpTape(&tape); @@ -5090,7 +5090,7 @@ static void Execute_Command(char *command) str_ptr++; if (*str_ptr == '\0') - Error(ERR_EXIT, "cannot find MODE in command '%s'", command); + Fail("cannot find MODE in command '%s'", command); global.patchtapes_mode = str_ptr; // store patch mode @@ -5135,7 +5135,7 @@ static void Execute_Command(char *command) if (strEqual(global.patchtapes_mode, "help")) global.patchtapes_leveldir = UNDEFINED_LEVELSET; else - Error(ERR_EXIT, "cannot find LEVELDIR in command '%s'", command); + Fail("cannot find LEVELDIR in command '%s'", command); } program.headless = TRUE; @@ -5161,8 +5161,8 @@ static void Execute_Command(char *command) global.create_images_dir = getStringCopy(&command[14]); if (access(global.create_images_dir, W_OK) != 0) - Error(ERR_EXIT, "image target directory '%s' not found or not writable", - global.create_images_dir); + Fail("image target directory '%s' not found or not writable", + global.create_images_dir); } else if (strPrefix(command, "create CE image ")) { @@ -5172,7 +5172,7 @@ static void Execute_Command(char *command) } else { - Error(ERR_EXIT_HELP, "unrecognized command '%s'", command); + FailWithHelp("unrecognized command '%s'", command); } // disable networking if any valid command was recognized @@ -5463,7 +5463,7 @@ static void InitGfx(void) } if (filename_font_initial == NULL) // should not happen - Error(ERR_EXIT, "cannot get filename for '%s'", CONFIG_TOKEN_FONT_INITIAL); + Fail("cannot get filename for '%s'", CONFIG_TOKEN_FONT_INITIAL); InitGfxBuffers(); InitGfxCustomArtworkInfo(); @@ -5549,7 +5549,7 @@ static void InitGfx(void) } if (filename_anim_initial == NULL) // should not happen - Error(ERR_EXIT, "cannot get filename for '%s'", CONFIG_TOKEN_GLOBAL_BUSY); + Fail("cannot get filename for '%s'", CONFIG_TOKEN_GLOBAL_BUSY); anim_initial.bitmaps = checked_calloc(sizeof(Bitmap *) * NUM_IMG_BITMAP_POINTERS); diff --git a/src/libgame/gadgets.c b/src/libgame/gadgets.c index 3ac1f9d5..56c359bc 100644 --- a/src/libgame/gadgets.c +++ b/src/libgame/gadgets.c @@ -78,7 +78,7 @@ static int getNewGadgetID(void) } if (next_free_gadget_id <= 0) // cannot get new gadget id - Error(ERR_EXIT, "too much gadgets -- this should not happen"); + Fail("too much gadgets -- this should not happen"); return id; } @@ -1207,7 +1207,7 @@ static void HandleGadgetTags(struct GadgetInfo *gi, int first_tag, va_list ap) break; default: - Error(ERR_EXIT, "HandleGadgetTags(): unknown tag %d", tag); + Fail("HandleGadgetTags(): unknown tag %d", tag); } tag = va_arg(ap, int); // read next tag @@ -1268,7 +1268,7 @@ static void HandleGadgetTags(struct GadgetInfo *gi, int first_tag, va_list ap) gi->height = 2 * border_ysize + font_height; if (gi->selectbox.options == NULL) - Error(ERR_EXIT, "selectbox gadget incomplete (missing options array)"); + Fail("selectbox gadget incomplete (missing options array)"); gi->selectbox.num_values = 0; while (gi->selectbox.options[gi->selectbox.num_values].text != NULL) @@ -1330,7 +1330,7 @@ static void HandleGadgetTags(struct GadgetInfo *gi, int first_tag, va_list ap) if (gi->width == 0 || gi->height == 0 || gs->items_max == 0 || gs->items_visible == 0) - Error(ERR_EXIT, "scrollbar gadget incomplete (missing tags)"); + Fail("scrollbar gadget incomplete (missing tags)"); // calculate internal scrollbar values gs->size_min = (gi->type == GD_TYPE_SCROLLBAR_VERTICAL ? diff --git a/src/libgame/misc.c b/src/libgame/misc.c index b71fee31..3946cd73 100644 --- a/src/libgame/misc.c +++ b/src/libgame/misc.c @@ -347,6 +347,15 @@ static void vLog(int log_level, char *mode, char *format, va_list ap) vprintf_log(format, ap); } +static void Log(int log_level, char *mode, char *format, ...) +{ + va_list ap; + + va_start(ap, format); + vLog(log_level, mode, format, ap); + va_end(ap); +} + void Debug(char *mode, char *format, ...) { va_list ap; @@ -374,6 +383,46 @@ void Warn(char *format, ...) va_end(ap); } +void Fail(char *format, ...) +{ + va_list ap; + + va_start(ap, format); + vLog(LOG_FATAL, NULL, format, ap); + va_end(ap); + + if (!network.is_server_thread) + { + va_start(ap, format); + program.exit_message_function(format, ap); + va_end(ap); + } + + Log(LOG_FATAL, NULL, "aborting"); + + // network server thread: normal exit + if (network.is_server_thread) + exit(1); + + // main process: clean up stuff + program.exit_function(1); +} + +void FailWithHelp(char *format, ...) +{ + va_list ap; + + va_start(ap, format); + vLog(LOG_FATAL, NULL, format, ap); + va_end(ap); + + Log(LOG_FATAL, NULL, "try option '--help' for more information"); + Log(LOG_FATAL, NULL, "aborting"); + + // main process: clean up stuff + program.exit_function(1); +} + // ---------------------------------------------------------------------------- // string functions @@ -1093,7 +1142,7 @@ void GetOptions(int argc, char *argv[], int option_len = strlen(option); if (option_len >= MAX_OPTION_LEN) - Error(ERR_EXIT_HELP, "unrecognized option '%s'", option); + FailWithHelp("unrecognized option '%s'", option); strcpy(option_str, option); // copy argument into buffer option = option_str; @@ -1111,14 +1160,14 @@ void GetOptions(int argc, char *argv[], { *option_arg++ = '\0'; // cut argument from option if (*option_arg == '\0') // no argument after '=' - Error(ERR_EXIT_HELP, "option '%s' has invalid argument", option_str); + FailWithHelp("option '%s' has invalid argument", option_str); } option_len = strlen(option); if (strEqual(option, "-")) { - Error(ERR_EXIT_HELP, "unrecognized option '%s'", option); + FailWithHelp("unrecognized option '%s'", option); } else if (strncmp(option, "-help", option_len) == 0) { @@ -1129,7 +1178,7 @@ void GetOptions(int argc, char *argv[], else if (strncmp(option, "-basepath", option_len) == 0) { if (option_arg == NULL) - Error(ERR_EXIT_HELP, "option '%s' requires an argument", option_str); + FailWithHelp("option '%s' requires an argument", option_str); // this should be extended to separate options for ro and rw data options.ro_base_directory = ro_base_path = getStringCopy(option_arg); @@ -1148,7 +1197,7 @@ void GetOptions(int argc, char *argv[], else if (strncmp(option, "-levels", option_len) == 0) { if (option_arg == NULL) - Error(ERR_EXIT_HELP, "option '%s' requires an argument", option_str); + FailWithHelp("option '%s' requires an argument", option_str); options.level_directory = getStringCopy(option_arg); if (option_arg == next_option) @@ -1157,7 +1206,7 @@ void GetOptions(int argc, char *argv[], else if (strncmp(option, "-graphics", option_len) == 0) { if (option_arg == NULL) - Error(ERR_EXIT_HELP, "option '%s' requires an argument", option_str); + FailWithHelp("option '%s' requires an argument", option_str); options.graphics_directory = getStringCopy(option_arg); if (option_arg == next_option) @@ -1166,7 +1215,7 @@ void GetOptions(int argc, char *argv[], else if (strncmp(option, "-sounds", option_len) == 0) { if (option_arg == NULL) - Error(ERR_EXIT_HELP, "option '%s' requires an argument", option_str); + FailWithHelp("option '%s' requires an argument", option_str); options.sounds_directory = getStringCopy(option_arg); if (option_arg == next_option) @@ -1175,7 +1224,7 @@ void GetOptions(int argc, char *argv[], else if (strncmp(option, "-music", option_len) == 0) { if (option_arg == NULL) - Error(ERR_EXIT_HELP, "option '%s' requires an argument", option_str); + FailWithHelp("option '%s' requires an argument", option_str); options.music_directory = getStringCopy(option_arg); if (option_arg == next_option) @@ -1219,7 +1268,7 @@ void GetOptions(int argc, char *argv[], else if (strncmp(option, "-execute", option_len) == 0) { if (option_arg == NULL) - Error(ERR_EXIT_HELP, "option '%s' requires an argument", option_str); + FailWithHelp("option '%s' requires an argument", option_str); options.execute_command = getStringCopy(option_arg); if (option_arg == next_option) @@ -1236,7 +1285,7 @@ void GetOptions(int argc, char *argv[], #endif else if (*option == '-') { - Error(ERR_EXIT_HELP, "unrecognized option '%s'", option_str); + FailWithHelp("unrecognized option '%s'", option_str); } else if (options.server_host == NULL) { @@ -1246,10 +1295,10 @@ void GetOptions(int argc, char *argv[], { options.server_port = atoi(*options_left); if (options.server_port < 1024) - Error(ERR_EXIT_HELP, "bad port number '%d'", options.server_port); + FailWithHelp("bad port number '%d'", options.server_port); } else - Error(ERR_EXIT_HELP, "too many arguments"); + FailWithHelp("too many arguments"); options_left++; } @@ -1376,7 +1425,7 @@ void *checked_malloc(unsigned int size) ptr = malloc(size); if (ptr == NULL) - Error(ERR_EXIT, "cannot allocate %d bytes -- out of memory", size); + Fail("cannot allocate %d bytes -- out of memory", size); return ptr; } @@ -1388,7 +1437,7 @@ void *checked_calloc(unsigned int size) ptr = calloc(1, size); if (ptr == NULL) - Error(ERR_EXIT, "cannot allocate %d bytes -- out of memory", size); + Fail("cannot allocate %d bytes -- out of memory", size); return ptr; } @@ -1398,7 +1447,7 @@ void *checked_realloc(void *ptr, unsigned int size) ptr = realloc(ptr, size); if (ptr == NULL) - Error(ERR_EXIT, "cannot allocate %d bytes -- out of memory", size); + Fail("cannot allocate %d bytes -- out of memory", size); return ptr; } @@ -3844,9 +3893,9 @@ void debug_print_timestamp(int counter_nr, char *message) float timestamp_interval; if (counter_nr < 0) - Error(ERR_EXIT, "debugging: invalid negative counter"); + Fail("debugging: invalid negative counter"); else if (counter_nr >= DEBUG_NUM_TIMESTAMPS) - Error(ERR_EXIT, "debugging: increase DEBUG_NUM_TIMESTAMPS in misc.c"); + Fail("debugging: increase DEBUG_NUM_TIMESTAMPS in misc.c"); #if DEBUG_TIME_IN_MICROSECONDS static double counter[DEBUG_NUM_TIMESTAMPS][2]; diff --git a/src/libgame/misc.h b/src/libgame/misc.h index ba82dad4..2fb49475 100644 --- a/src/libgame/misc.h +++ b/src/libgame/misc.h @@ -126,6 +126,8 @@ void PrintLineWithPrefix(char *, char *, int); void Debug(char *, char *, ...); void Info(char *, ...); void Warn(char *, ...); +void Fail(char *, ...); +void FailWithHelp(char *, ...); char *int2str(int, int); char *i_to_a(unsigned int); diff --git a/src/libgame/sdl.c b/src/libgame/sdl.c index ece4e3f7..a66049e9 100644 --- a/src/libgame/sdl.c +++ b/src/libgame/sdl.c @@ -360,7 +360,7 @@ SDL_Surface *SDLGetNativeSurface(SDL_Surface *surface) new_surface = SDL_ConvertSurface(surface, &format, 0); if (new_surface == NULL) - Error(ERR_EXIT, "SDL_ConvertSurface() failed: %s", SDL_GetError()); + Fail("SDL_ConvertSurface() failed: %s", SDL_GetError()); // workaround for a bug in SDL 2.0.12 (which does not convert the color key) if (SDLHasColorKey(surface) && !SDLHasColorKey(new_surface)) @@ -401,8 +401,7 @@ static SDL_Texture *SDLCreateTextureFromSurface(SDL_Surface *surface) SDL_Texture *texture = SDL_CreateTextureFromSurface(sdl_renderer, surface); if (texture == NULL) - Error(ERR_EXIT, "SDL_CreateTextureFromSurface() failed: %s", - SDL_GetError()); + Fail("SDL_CreateTextureFromSurface() failed: %s", SDL_GetError()); return texture; } @@ -443,7 +442,7 @@ void SDLInitVideoDisplay(void) // initialize SDL video if (SDL_InitSubSystem(SDL_INIT_VIDEO) < 0) - Error(ERR_EXIT, "SDL_InitSubSystem() failed: %s", SDL_GetError()); + Fail("SDL_InitSubSystem() failed: %s", SDL_GetError()); // set default SDL depth video.default_depth = 32; // (how to determine video depth in SDL2?) @@ -467,7 +466,7 @@ static void SDLInitVideoBuffer_VideoBuffer(boolean fullscreen) // open SDL video output device (window or fullscreen mode) if (!SDLSetVideoMode(fullscreen)) - Error(ERR_EXIT, "setting video mode failed"); + Fail("setting video mode failed"); // !!! SDL2 can only set the window icon if the window already exists !!! // set window icon @@ -913,7 +912,7 @@ void SDLCreateBitmapContent(Bitmap *bitmap, int width, int height, SDL_CreateRGBSurface(SURFACE_FLAGS, width, height, depth, 0,0,0, 0); if (surface == NULL) - Error(ERR_EXIT, "SDL_CreateRGBSurface() failed: %s", SDL_GetError()); + Fail("SDL_CreateRGBSurface() failed: %s", SDL_GetError()); SDLSetNativeSurface(&surface); @@ -2237,7 +2236,7 @@ static SDL_Surface *SDLGetOpaqueSurface(SDL_Surface *surface) return NULL; if ((new_surface = SDLGetNativeSurface(surface)) == NULL) - Error(ERR_EXIT, "SDLGetNativeSurface() failed"); + Fail("SDLGetNativeSurface() failed"); // remove alpha channel from native non-transparent surface, if defined SDLSetAlpha(new_surface, FALSE, 0); @@ -2304,8 +2303,7 @@ Bitmap *SDLLoadImage(char *filename) // load image to temporary surface if ((sdl_image_tmp = IMG_Load(filename)) == NULL) - Error(ERR_EXIT, "IMG_Load('%s') failed: %s", getBaseNamePtr(filename), - SDL_GetError()); + Fail("IMG_Load('%s') failed: %s", getBaseNamePtr(filename), SDL_GetError()); print_timestamp_time("IMG_Load"); @@ -2313,7 +2311,7 @@ Bitmap *SDLLoadImage(char *filename) // create native non-transparent surface for current image if ((new_bitmap->surface = SDLGetOpaqueSurface(sdl_image_tmp)) == NULL) - Error(ERR_EXIT, "SDLGetOpaqueSurface() failed"); + Fail("SDLGetOpaqueSurface() failed"); print_timestamp_time("SDLGetNativeSurface (opaque)"); @@ -2327,7 +2325,7 @@ Bitmap *SDLLoadImage(char *filename) // create native transparent surface for current image if ((new_bitmap->surface_masked = SDLGetNativeSurface(sdl_image_tmp)) == NULL) - Error(ERR_EXIT, "SDLGetNativeSurface() failed"); + Fail("SDLGetNativeSurface() failed"); print_timestamp_time("SDLGetNativeSurface (masked)"); @@ -2707,11 +2705,7 @@ void SDLInitJoysticks(void) SDL_SetHint(SDL_HINT_ACCELEROMETER_AS_JOYSTICK, "0"); if (SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER) < 0) - { - Error(ERR_EXIT, "SDL_Init() failed: %s", SDL_GetError()); - - return; - } + Fail("SDL_Init() failed: %s", SDL_GetError()); num_mappings = SDL_GameControllerAddMappingsFromFile(mappings_file_base); diff --git a/src/libgame/setup.c b/src/libgame/setup.c index 206db77e..4b28476a 100644 --- a/src/libgame/setup.c +++ b/src/libgame/setup.c @@ -1891,7 +1891,7 @@ SetupFileHash *newSetupFileHash(void) create_hashtable(16, 0.75, get_hash_from_key, keys_are_equal); if (new_hash == NULL) - Error(ERR_EXIT, "create_hashtable() failed -- out of memory"); + Fail("create_hashtable() failed -- out of memory"); return new_hash; } @@ -1924,7 +1924,7 @@ void setHashEntry(SetupFileHash *hash, char *token, char *value) // change value; if it does not exist, insert it as new if (!change_hash_entry(hash, token, value_copy)) if (!insert_hash_entry(hash, getStringCopy(token), value_copy)) - Error(ERR_EXIT, "cannot insert into hash -- aborting"); + Fail("cannot insert into hash -- aborting"); } char *removeHashEntry(SetupFileHash *hash, char *token) @@ -3540,7 +3540,7 @@ void LoadLevelInfo(void) leveldir_current = getFirstValidTreeInfoEntry(leveldir_first); if (leveldir_first == NULL) - Error(ERR_EXIT, "cannot find any valid level series in any directory"); + Fail("cannot find any valid level series in any directory"); sortTreeInfo(&leveldir_first); @@ -4053,7 +4053,7 @@ void AddTreeSetToTreeInfo(TreeInfo *tree_node, char *tree_dir, char *tree_subdir_new, int type) { if (!AddTreeSetToTreeInfoExt(tree_node, tree_dir, tree_subdir_new, type)) - Error(ERR_EXIT, "internal tree info structure corrupted -- aborting"); + Fail("internal tree info structure corrupted -- aborting"); } void AddUserLevelSetToLevelInfo(char *level_subdir_new) @@ -4095,7 +4095,7 @@ TreeInfo *getArtworkTreeInfoForUserLevelSet(int type) ti = getTreeInfoFromIdentifier(artwork_first_node, ARTWORK_DEFAULT_SUBDIR(type)); if (ti == NULL) - Error(ERR_EXIT, "cannot find default graphics -- should not happen"); + Fail("cannot find default graphics -- should not happen"); } return ti; diff --git a/src/libgame/system.c b/src/libgame/system.c index 076ea586..4e500cb2 100644 --- a/src/libgame/system.c +++ b/src/libgame/system.c @@ -194,7 +194,7 @@ void InitPlatformDependentStuff(void) int sdl_init_flags = SDL_INIT_EVENTS | SDL_INIT_NOPARACHUTE; if (SDL_Init(sdl_init_flags) < 0) - Error(ERR_EXIT, "SDL_Init() failed: %s", SDL_GetError()); + Fail("SDL_Init() failed: %s", SDL_GetError()); SDLNet_Init(); } @@ -1157,10 +1157,10 @@ Bitmap *LoadCustomImage(char *basename) Bitmap *new_bitmap; if (filename == NULL) - Error(ERR_EXIT, "LoadCustomImage(): cannot find file '%s'", basename); + Fail("LoadCustomImage(): cannot find file '%s'", basename); if ((new_bitmap = LoadImage(filename)) == NULL) - Error(ERR_EXIT, "LoadImage('%s') failed: %s", basename, GetError()); + Fail("LoadImage('%s') failed: %s", basename, GetError()); return new_bitmap; } diff --git a/src/libgame/text.c b/src/libgame/text.c index dbec20df..c10583d3 100644 --- a/src/libgame/text.c +++ b/src/libgame/text.c @@ -169,7 +169,7 @@ void DrawTextF(int x, int y, int font_nr, char *format, ...) va_end(ap); if (strlen(buffer) > MAX_OUTPUT_LINESIZE) - Error(ERR_EXIT, "string too long in DrawTextF() -- aborting"); + Fail("string too long in DrawTextF() -- aborting"); DrawText(gfx.sx + x, gfx.sy + y, buffer, font_nr); } @@ -184,7 +184,7 @@ void DrawTextFCentered(int y, int font_nr, char *format, ...) va_end(ap); if (strlen(buffer) > MAX_OUTPUT_LINESIZE) - Error(ERR_EXIT, "string too long in DrawTextFCentered() -- aborting"); + Fail("string too long in DrawTextFCentered() -- aborting"); DrawText(gfx.sx + (gfx.sxsize - getTextWidth(buffer, font_nr)) / 2, gfx.sy + y, buffer, font_nr); diff --git a/src/netserv.c b/src/netserv.c index 9ed0291c..1f0663fd 100644 --- a/src/netserv.c +++ b/src/netserv.c @@ -864,28 +864,22 @@ void NetworkServer(int port, int serveronly) #endif if (SDLNet_ResolveHost(&ip, NULL, port) == -1) - Error(ERR_EXIT_NETWORK_SERVER, "SDLNet_ResolveHost() failed: %s", - SDLNet_GetError()); + Fail("SDLNet_ResolveHost() failed: %s", SDLNet_GetError()); if ((fds = SDLNet_AllocSocketSet(MAX_PLAYERS + 1 + 1)) == NULL) - Error(ERR_EXIT_NETWORK_SERVER, "SDLNet_AllocSocketSet() failed: %s"), - SDLNet_GetError(); + Fail("SDLNet_AllocSocketSet() failed: %s"), SDLNet_GetError(); if ((lfd = SDLNet_TCP_Open(&ip)) == NULL) - Error(ERR_EXIT_NETWORK_SERVER, "SDLNet_TCP_Open() failed: %s"), - SDLNet_GetError(); + Fail("SDLNet_TCP_Open() failed: %s"), SDLNet_GetError(); if (SDLNet_TCP_AddSocket(fds, lfd) == -1) - Error(ERR_EXIT_NETWORK_SERVER, "SDLNet_TCP_AddSocket() failed: %s"), - SDLNet_GetError(); + Fail("SDLNet_TCP_AddSocket() failed: %s"), SDLNet_GetError(); if ((udp = SDLNet_UDP_Open(port)) == NULL) - Error(ERR_EXIT_NETWORK_SERVER, "SDLNet_UDP_Open() failed: %s", - SDLNet_GetError()); + Fail("SDLNet_UDP_Open() failed: %s", SDLNet_GetError()); if (SDLNet_UDP_AddSocket(fds, udp) == -1) - Error(ERR_EXIT_NETWORK_SERVER, "SDLNet_TCP_AddSocket() failed: %s"), - SDLNet_GetError(); + Fail("SDLNet_TCP_AddSocket() failed: %s"), SDLNet_GetError(); Debug("network:server", "started up, listening on port %d", port); Debug("network:server", "using protocol version %d.%d.%d", diff --git a/src/network.c b/src/network.c index a21c16e7..2905dc57 100644 --- a/src/network.c +++ b/src/network.c @@ -151,8 +151,7 @@ static struct NetworkClientPlayerInfo *getNetworkPlayer(int player_nr) break; if (player == NULL) // should not happen - Error(ERR_EXIT, "protocol error: reference to non-existing player %d", - player_nr); + Fail("protocol error: reference to non-existing player %d", player_nr); return player; } @@ -217,15 +216,14 @@ boolean ConnectToServer(char *hostname, int port) SDLNet_SocketSet udp_socket_set = SDLNet_AllocSocketSet(1); if (!udp_socket_set) - Error(ERR_EXIT, "SDLNet_AllocSocketSet() failed: %s"), SDLNet_GetError(); + Fail("SDLNet_AllocSocketSet() failed: %s"), SDLNet_GetError(); udp = SDLNet_UDP_Open(0); if (!udp) - Error(ERR_EXIT, "SDLNet_UDP_Open() failed: %s", SDLNet_GetError()); + Fail("SDLNet_UDP_Open() failed: %s", SDLNet_GetError()); if (SDLNet_UDP_AddSocket(udp_socket_set, udp) == -1) - Error(ERR_EXIT_NETWORK_SERVER, "SDLNet_TCP_AddSocket() failed: %s"), - SDLNet_GetError(); + Fail("SDLNet_TCP_AddSocket() failed: %s"), SDLNet_GetError(); char *data_ptr = "network server UDB broadcast"; int data_len = strlen(data_ptr) + 1; @@ -548,7 +546,7 @@ static void Handle_OP_YOUR_NUMBER(void) } if (first_player.nr > MAX_PLAYERS) - Error(ERR_EXIT, "sorry, more than %d players not allowed", MAX_PLAYERS); + Fail("sorry, more than %d players not allowed", MAX_PLAYERS); Debug("network:client", "you get client # %d", new_client_nr); @@ -641,7 +639,7 @@ static void Handle_OP_PLAYER_CONNECTED(void) for (player = &first_player; player; player = player->next) { if (player->nr == new_client_nr) - Error(ERR_EXIT, "multiplayer server sent duplicate player id"); + Fail("multiplayer server sent duplicate player id"); last_player = player; } @@ -856,7 +854,7 @@ static void Handle_OP_LEVEL_FILE(void) leveldir_identifier = getStringCopy(getNetworkBufferString(read_buffer)); if (hasPathSeparator(leveldir_identifier)) - Error(ERR_EXIT, "protocol error: invalid filename from network client"); + Fail("protocol error: invalid filename from network client"); InitNetworkLevelDirectory(leveldir_identifier); @@ -869,7 +867,7 @@ static void Handle_OP_LEVEL_FILE(void) file_info->filename = getPath2(network_level_dir, file_info->basename); if (hasPathSeparator(file_info->basename)) - Error(ERR_EXIT, "protocol error: invalid filename from network client"); + Fail("protocol error: invalid filename from network client"); int num_bytes = getNetworkBufferFile(read_buffer, file_info->filename); @@ -886,7 +884,7 @@ static void Handle_OP_LEVEL_FILE(void) tmpl_info->filename = getPath2(network_level_dir, tmpl_info->basename); if (hasPathSeparator(tmpl_info->basename)) - Error(ERR_EXIT, "protocol error: invalid filename from network client"); + Fail("protocol error: invalid filename from network client"); getNetworkBufferFile(read_buffer, tmpl_info->filename); diff --git a/src/screens.c b/src/screens.c index 421238be..41292512 100644 --- a/src/screens.c +++ b/src/screens.c @@ -8714,7 +8714,7 @@ static void CreateScreenMenubuttons(void) GDI_END); if (gi == NULL) - Error(ERR_EXIT, "cannot create gadget"); + Fail("cannot create gadget"); screen_gadget[id] = gi; } @@ -8782,7 +8782,7 @@ static void CreateScreenScrollbuttons(void) GDI_END); if (gi == NULL) - Error(ERR_EXIT, "cannot create gadget"); + Fail("cannot create gadget"); screen_gadget[id] = gi; } @@ -8863,7 +8863,7 @@ static void CreateScreenScrollbars(void) GDI_END); if (gi == NULL) - Error(ERR_EXIT, "cannot create gadget"); + Fail("cannot create gadget"); screen_gadget[id] = gi; } @@ -8909,7 +8909,7 @@ static void CreateScreenTextInputGadgets(void) GDI_END); if (gi == NULL) - Error(ERR_EXIT, "cannot create gadget"); + Fail("cannot create gadget"); screen_gadget[id] = gi; } diff --git a/src/tape.c b/src/tape.c index 5e7bca15..ac96ef96 100644 --- a/src/tape.c +++ b/src/tape.c @@ -1324,8 +1324,7 @@ void AutoPlayTapes(void) global.autoplay_leveldir); if (autoplay_leveldir == NULL) - Error(ERR_EXIT, "no such level identifier: '%s'", - global.autoplay_leveldir); + Fail("no such level identifier: '%s'", global.autoplay_leveldir); leveldir_current = autoplay_leveldir; @@ -1567,8 +1566,7 @@ void PatchTapes(void) global.patchtapes_leveldir); if (patchtapes_leveldir == NULL) - Error(ERR_EXIT, "no such level identifier: '%s'", - global.patchtapes_leveldir); + Fail("no such level identifier: '%s'", global.patchtapes_leveldir); leveldir_current = patchtapes_leveldir; @@ -1713,7 +1711,7 @@ void CreateTapeButtons(void) GDI_END); if (gi == NULL) - Error(ERR_EXIT, "cannot create gadget"); + Fail("cannot create gadget"); tape_gadget[id] = gi; } diff --git a/src/tools.c b/src/tools.c index b3eacd95..2c30df83 100644 --- a/src/tools.c +++ b/src/tools.c @@ -1468,7 +1468,7 @@ void FloodFillLevelExt(int from_x, int from_y, int fill_element, safety++; if (safety > max_fieldx * max_fieldy) - Error(ERR_EXIT, "Something went wrong in 'FloodFill()'. Please debug."); + Fail("Something went wrong in 'FloodFill()'. Please debug."); old_element = field[from_x][from_y]; field[from_x][from_y] = fill_element; @@ -5680,7 +5680,7 @@ void CreateToolButtons(void) GDI_END); if (gi == NULL) - Error(ERR_EXIT, "cannot create gadget"); + Fail("cannot create gadget"); tool_gadget[id] = gi; } -- 2.34.1