diff options
author | glx <glx@openttd.org> | 2008-06-05 20:54:52 +0000 |
---|---|---|
committer | glx <glx@openttd.org> | 2008-06-05 20:54:52 +0000 |
commit | b60a1326bf3ea9b9e0235cf18cdcd964c758a8bf (patch) | |
tree | 62bef57de81c1ddcc691d5de5e8db395615bdacc /src | |
parent | bb758700a87b19e47c6ef7aa28280ca05badd62f (diff) | |
download | openttd-b60a1326bf3ea9b9e0235cf18cdcd964c758a8bf.tar.xz |
(svn r13390) -Codechange: introduce usererror() for fatal but not openttd related errors. Now all error() will 'crash' openttd after showing the message in win32 releases (MSVC), creating a crash.log and crash.dmp (like the '!' hack used before). On the other hand, usererror() will just close the game. So use error() only when it can be helpful to debugging, else use usererror().
Diffstat (limited to 'src')
-rw-r--r-- | src/driver.cpp | 6 | ||||
-rw-r--r-- | src/fileio.cpp | 2 | ||||
-rw-r--r-- | src/gfxinit.cpp | 2 | ||||
-rw-r--r-- | src/network/network_server.cpp | 6 | ||||
-rw-r--r-- | src/newgrf.cpp | 4 | ||||
-rw-r--r-- | src/openttd.cpp | 42 | ||||
-rw-r--r-- | src/os2.cpp | 2 | ||||
-rw-r--r-- | src/roadveh_cmd.cpp | 2 | ||||
-rw-r--r-- | src/sound/win32_s.cpp | 4 | ||||
-rw-r--r-- | src/spritecache.cpp | 4 | ||||
-rw-r--r-- | src/stdafx.h | 1 | ||||
-rw-r--r-- | src/strings.cpp | 8 | ||||
-rw-r--r-- | src/town_cmd.cpp | 2 | ||||
-rw-r--r-- | src/train_cmd.cpp | 2 | ||||
-rw-r--r-- | src/unix.cpp | 2 | ||||
-rw-r--r-- | src/video/dedicated_v.cpp | 4 | ||||
-rw-r--r-- | src/video/sdl_v.cpp | 4 | ||||
-rw-r--r-- | src/video/win32_v.cpp | 10 | ||||
-rw-r--r-- | src/win32.cpp | 6 |
19 files changed, 67 insertions, 46 deletions
diff --git a/src/driver.cpp b/src/driver.cpp index 202b84fab..6e9c2c54d 100644 --- a/src/driver.cpp +++ b/src/driver.cpp @@ -87,7 +87,7 @@ const Driver *DriverFactoryBase::SelectDriver(const char *name, Driver::Type typ delete newd; } } - error("Couldn't find any suitable %s driver", GetDriverTypeName(type)); + usererror("Couldn't find any suitable %s driver", GetDriverTypeName(type)); } else { char *parm; char buffer[256]; @@ -125,7 +125,7 @@ const Driver *DriverFactoryBase::SelectDriver(const char *name, Driver::Type typ const char *err = newd->Start(parms); if (err != NULL) { delete newd; - error("Unable to load driver '%s'. The error was: %s", d->name, err); + usererror("Unable to load driver '%s'. The error was: %s", d->name, err); } DEBUG(driver, 1, "Successfully loaded %s driver '%s'", GetDriverTypeName(type), d->name); @@ -133,7 +133,7 @@ const Driver *DriverFactoryBase::SelectDriver(const char *name, Driver::Type typ *GetActiveDriver(type) = newd; return newd; } - error("No such %s driver: %s\n", GetDriverTypeName(type), buffer); + usererror("No such %s driver: %s\n", GetDriverTypeName(type), buffer); } } diff --git a/src/fileio.cpp b/src/fileio.cpp index c35c4ae96..f68f6693e 100644 --- a/src/fileio.cpp +++ b/src/fileio.cpp @@ -186,7 +186,7 @@ void FioOpenFile(int slot, const char *filename) FioFreeHandle(); #endif /* LIMITED_FDS */ f = FioFOpenFile(filename); - if (f == NULL) error("Cannot open file '%s'", filename); + if (f == NULL) usererror("Cannot open file '%s'", filename); uint32 pos = ftell(f); FioCloseFile(slot); // if file was opened before, close it diff --git a/src/gfxinit.cpp b/src/gfxinit.cpp index 8b04b1517..ef8a4d5b0 100644 --- a/src/gfxinit.cpp +++ b/src/gfxinit.cpp @@ -55,7 +55,7 @@ static uint LoadGrfFile(const char *filename, uint load_index, int file_index) load_index++; sprite_id++; if (load_index >= MAX_SPRITES) { - error("Too many sprites. Recompile with higher MAX_SPRITES value or remove some custom GRF files."); + usererror("Too many sprites. Recompile with higher MAX_SPRITES value or remove some custom GRF files."); } } DEBUG(sprite, 2, "Currently %i sprites are loaded", load_index); diff --git a/src/network/network_server.cpp b/src/network/network_server.cpp index 16f77f610..b0f3a98c8 100644 --- a/src/network/network_server.cpp +++ b/src/network/network_server.cpp @@ -323,12 +323,12 @@ DEF_SERVER_SEND_COMMAND(PACKET_SERVER_MAP) Packet *p; // Make a dump of the current game - if (SaveOrLoad(filename, SL_SAVE, AUTOSAVE_DIR) != SL_OK) error("network savedump failed"); + if (SaveOrLoad(filename, SL_SAVE, AUTOSAVE_DIR) != SL_OK) usererror("network savedump failed"); file_pointer = FioFOpenFile(filename, "rb", AUTOSAVE_DIR); fseek(file_pointer, 0, SEEK_END); - if (ftell(file_pointer) == 0) error("network savedump failed - zero sized savegame?"); + if (ftell(file_pointer) == 0) usererror("network savedump failed - zero sized savegame?"); // Now send the _frame_counter and how many packets are coming p = NetworkSend_Init(PACKET_SERVER_MAP); @@ -355,7 +355,7 @@ DEF_SERVER_SEND_COMMAND(PACKET_SERVER_MAP) p->Send_uint8(MAP_PACKET_NORMAL); res = (int)fread(p->buffer + p->size, 1, SEND_MTU - p->size, file_pointer); - if (ferror(file_pointer)) error("Error reading temporary network savegame!"); + if (ferror(file_pointer)) usererror("Error reading temporary network savegame!"); p->size += res; cs->Send_Packet(p); diff --git a/src/newgrf.cpp b/src/newgrf.cpp index aa7496b92..5fe787877 100644 --- a/src/newgrf.cpp +++ b/src/newgrf.cpp @@ -5783,7 +5783,7 @@ void LoadNewGRFFile(GRFConfig *config, uint file_index, GrfLoadingStage stage) * processed once at initialization. */ if (stage != GLS_FILESCAN && stage != GLS_SAFETYSCAN && stage != GLS_LABELSCAN) { _cur_grffile = GetFileByFilename(filename); - if (_cur_grffile == NULL) error("File '%s' lost in cache.\n", filename); + if (_cur_grffile == NULL) usererror("File '%s' lost in cache.\n", filename); if (stage == GLS_RESERVE && config->status != GCS_INITIALISED) return; if (stage == GLS_ACTIVATION && !HasBit(config->flags, GCF_RESERVED)) return; _cur_grffile->is_ottdfile = config->IsOpenTTDBaseGRF(); @@ -5989,7 +5989,7 @@ void LoadNewGRF(uint load_index, uint file_index) if (stage > GLS_INIT && HasBit(c->flags, GCF_INIT_ONLY)) continue; /* @todo usererror() */ - if (!FioCheckFileExists(c->filename)) error("NewGRF file is missing '%s'", c->filename); + if (!FioCheckFileExists(c->filename)) usererror("NewGRF file is missing '%s'", c->filename); if (stage == GLS_LABELSCAN) InitNewGRFFile(c, _cur_spriteid); LoadNewGRFFile(c, slot++, stage); diff --git a/src/openttd.cpp b/src/openttd.cpp index 2bf7ce337..1861d3cd3 100644 --- a/src/openttd.cpp +++ b/src/openttd.cpp @@ -99,11 +99,31 @@ void CallWindowTickEvent(); extern void SetDifficultyLevel(int mode, DifficultySettings *gm_opt); extern Player* DoStartupNewPlayer(bool is_ai); -extern void ShowOSErrorBox(const char *buf); +extern void ShowOSErrorBox(const char *buf, bool system); extern void InitializeRailGUI(); /** - * Error handling for fatal errors. + * Error handling for fatal user errors. + * @param s the string to print. + * @note Does NEVER return. + */ +void CDECL usererror(const char *s, ...) +{ + va_list va; + char buf[512]; + + va_start(va, s); + vsnprintf(buf, lengthof(buf), s, va); + va_end(va); + + ShowOSErrorBox(buf, false); + if (_video_driver != NULL) _video_driver->Stop(); + + exit(1); +} + +/** + * Error handling for fatal non-user errors. * @param s the string to print. * @note Does NEVER return. */ @@ -116,7 +136,7 @@ void CDECL error(const char *s, ...) vsnprintf(buf, lengthof(buf), s, va); va_end(va); - ShowOSErrorBox(buf); + ShowOSErrorBox(buf, true); if (_video_driver != NULL) _video_driver->Stop(); assert(0); @@ -524,30 +544,30 @@ int ttd_main(int argc, char *argv[]) DEBUG(misc, 1, "Loading blitter..."); if (BlitterFactoryBase::SelectBlitter(_ini_blitter) == NULL) StrEmpty(_ini_blitter) ? - error("Failed to autoprobe blitter") : - error("Failed to select requested blitter '%s'; does it exist?", _ini_blitter); + usererror("Failed to autoprobe blitter") : + usererror("Failed to select requested blitter '%s'; does it exist?", _ini_blitter); DEBUG(driver, 1, "Loading drivers..."); _sound_driver = (SoundDriver*)SoundDriverFactoryBase::SelectDriver(_ini_sounddriver, Driver::DT_SOUND); if (_sound_driver == NULL) { StrEmpty(_ini_sounddriver) ? - error("Failed to autoprobe sound driver") : - error("Failed to select requested sound driver '%s'", _ini_sounddriver); + usererror("Failed to autoprobe sound driver") : + usererror("Failed to select requested sound driver '%s'", _ini_sounddriver); } _music_driver = (MusicDriver*)MusicDriverFactoryBase::SelectDriver(_ini_musicdriver, Driver::DT_MUSIC); if (_music_driver == NULL) { StrEmpty(_ini_musicdriver) ? - error("Failed to autoprobe music driver") : - error("Failed to select requested music driver '%s'", _ini_musicdriver); + usererror("Failed to autoprobe music driver") : + usererror("Failed to select requested music driver '%s'", _ini_musicdriver); } _video_driver = (VideoDriver*)VideoDriverFactoryBase::SelectDriver(_ini_videodriver, Driver::DT_VIDEO); if (_video_driver == NULL) { StrEmpty(_ini_videodriver) ? - error("Failed to autoprobe video driver") : - error("Failed to select requested video driver '%s'", _ini_videodriver); + usererror("Failed to autoprobe video driver") : + usererror("Failed to select requested video driver '%s'", _ini_videodriver); } _savegame_sort_order = SORT_BY_DATE | SORT_DESCENDING; diff --git a/src/os2.cpp b/src/os2.cpp index 3e54bb5ad..d57708e31 100644 --- a/src/os2.cpp +++ b/src/os2.cpp @@ -145,7 +145,7 @@ void ShowInfo(const char *str) WinTerminate(hab); } -void ShowOSErrorBox(const char *buf) +void ShowOSErrorBox(const char *buf, bool system) { HAB hab; HMQ hmq; diff --git a/src/roadveh_cmd.cpp b/src/roadveh_cmd.cpp index 6f4e7cc29..35fc275d5 100644 --- a/src/roadveh_cmd.cpp +++ b/src/roadveh_cmd.cpp @@ -1468,7 +1468,7 @@ static bool IndividualRoadVehicleController(Vehicle *v, const Vehicle *prev) } if (dir == INVALID_TRACKDIR) { - if (!IsRoadVehFront(v)) error("!Disconnecting road vehicle."); + if (!IsRoadVehFront(v)) error("Disconnecting road vehicle."); v->cur_speed = 0; return false; } diff --git a/src/sound/win32_s.cpp b/src/sound/win32_s.cpp index 66a7fde03..20569bd25 100644 --- a/src/sound/win32_s.cpp +++ b/src/sound/win32_s.cpp @@ -24,7 +24,7 @@ static void PrepareHeader(WAVEHDR *hdr) hdr->lpData = MallocT<char>(_bufsize * 4); if (hdr->lpData == NULL || waveOutPrepareHeader(_waveout, hdr, sizeof(WAVEHDR)) != MMSYSERR_NOERROR) - error("waveOutPrepareHeader failed"); + usererror("waveOutPrepareHeader failed"); } static void FillHeaders() @@ -35,7 +35,7 @@ static void FillHeaders() if (!(hdr->dwFlags & WHDR_INQUEUE)) { MxMixSamples(hdr->lpData, hdr->dwBufferLength / 4); if (waveOutWrite(_waveout, hdr, sizeof(WAVEHDR)) != MMSYSERR_NOERROR) - error("waveOutWrite failed"); + usererror("waveOutWrite failed"); } } } diff --git a/src/spritecache.cpp b/src/spritecache.cpp index adc0145df..248a6d5ef 100644 --- a/src/spritecache.cpp +++ b/src/spritecache.cpp @@ -169,7 +169,7 @@ static void* ReadSprite(SpriteCache *sc, SpriteID id, bool real_sprite) static byte warning_level = 0; DEBUG(sprite, warning_level, "Tried to load non sprite #%d as a real sprite. Probable cause: NewGRF interference", id); warning_level = 6; - if (id == SPR_IMG_QUERY) error("Uhm, would you be so kind not to load a NewGRF that makes the 'query' sprite a non- sprite?"); + if (id == SPR_IMG_QUERY) usererror("Uhm, would you be so kind not to load a NewGRF that makes the 'query' sprite a non- sprite?"); return (void*)GetSprite(SPR_IMG_QUERY); } @@ -246,7 +246,7 @@ bool LoadNextSprite(int load_index, byte file_slot, uint file_sprite_id) if (!ReadSpriteHeaderSkipData()) return false; if (load_index >= MAX_SPRITES) { - error("Tried to load too many sprites (#%d; max %d)", load_index, MAX_SPRITES); + usererror("Tried to load too many sprites (#%d; max %d)", load_index, MAX_SPRITES); } sc = AllocateSpriteCache(load_index); diff --git a/src/stdafx.h b/src/stdafx.h index 9eb1a4e11..f6ef278c4 100644 --- a/src/stdafx.h +++ b/src/stdafx.h @@ -317,6 +317,7 @@ assert_compile(sizeof(uint8) == 1); #define CloseConnection OTTD_CloseConnection #endif /* __APPLE__ */ +void NORETURN CDECL usererror(const char *str, ...); void NORETURN CDECL error(const char *str, ...); #define NOT_REACHED() error("NOT_REACHED triggered at line %i of %s", __LINE__, __FILE__) diff --git a/src/strings.cpp b/src/strings.cpp index 49df9ed66..c0d8443ed 100644 --- a/src/strings.cpp +++ b/src/strings.cpp @@ -178,7 +178,7 @@ static char *GetStringWithArgs(char *buffr, uint string, const int64 *argv, cons if (index >= _langtab_num[tab]) { error( - "!String 0x%X is invalid. " + "String 0x%X is invalid. " "Probably because an old version of the .lng file.\n", string ); } @@ -1427,7 +1427,7 @@ void InitializeLanguagePacks() FioAppendDirectory(path, lengthof(path), sp, LANG_DIR); language_count += GetLanguageList(files, language_count, lengthof(files), path); } - if (language_count == 0) error("No available language packs (invalid versions?)"); + if (language_count == 0) usererror("No available language packs (invalid versions?)"); /* Acquire the locale of the current system */ const char *lang = GetCurrentLocale("LC_MESSAGES"); @@ -1463,7 +1463,7 @@ void InitializeLanguagePacks() dl->num++; } - if (dl->num == 0) error("Invalid version of language packs"); + if (dl->num == 0) usererror("Invalid version of language packs"); /* We haven't found the language in the config nor the one in the locale. * Now we set it to one of the fallback languages */ @@ -1471,7 +1471,7 @@ void InitializeLanguagePacks() chosen_language = (language_fallback != -1) ? language_fallback : en_GB_fallback; } - if (!ReadLanguagePack(chosen_language)) error("Can't read language pack '%s'", dl->ent[chosen_language].file); + if (!ReadLanguagePack(chosen_language)) usererror("Can't read language pack '%s'", dl->ent[chosen_language].file); } /** diff --git a/src/town_cmd.cpp b/src/town_cmd.cpp index 97c111461..a9256a1a5 100644 --- a/src/town_cmd.cpp +++ b/src/town_cmd.cpp @@ -1603,7 +1603,7 @@ bool GenerateTowns() if (num == 0 && CreateRandomTown(10000, TSM_RANDOM, 0) == NULL) { if (GetNumTowns() == 0) { /* XXX - can we handle that more gracefully? */ - if (_game_mode != GM_EDITOR) error("Could not generate any town"); + if (_game_mode != GM_EDITOR) usererror("Could not generate any town"); return false; } diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp index 788a204ce..8de0bb797 100644 --- a/src/train_cmd.cpp +++ b/src/train_cmd.cpp @@ -3113,7 +3113,7 @@ static void TrainController(Vehicle *v, Vehicle *nomove, bool update_image) invalid_rail: /* We've reached end of line?? */ - if (prev != NULL) error("!Disconnecting train"); + if (prev != NULL) error("Disconnecting train"); reverse_train_direction: v->load_unload_time_rem = 0; diff --git a/src/unix.cpp b/src/unix.cpp index 3ea6c2f5d..7fafd3d67 100644 --- a/src/unix.cpp +++ b/src/unix.cpp @@ -214,7 +214,7 @@ void ShowInfo(const char *str) fprintf(stderr, "%s\n", str); } -void ShowOSErrorBox(const char *buf) +void ShowOSErrorBox(const char *buf, bool system) { #if defined(__APPLE__) /* this creates an NSAlertPanel with the contents of 'buf' diff --git a/src/video/dedicated_v.cpp b/src/video/dedicated_v.cpp index 8af223e8e..1921205bb 100644 --- a/src/video/dedicated_v.cpp +++ b/src/video/dedicated_v.cpp @@ -107,10 +107,10 @@ static void CreateWindowsConsoleThread() /* Create event to signal when console input is ready */ _hInputReady = CreateEvent(NULL, false, false, NULL); _hWaitForInputHandling = CreateEvent(NULL, false, false, NULL); - if (_hInputReady == NULL || _hWaitForInputHandling == NULL) error("Cannot create console event!"); + if (_hInputReady == NULL || _hWaitForInputHandling == NULL) usererror("Cannot create console event!"); _hThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)CheckForConsoleInput, NULL, 0, &dwThreadId); - if (_hThread == NULL) error("Cannot create console thread!"); + if (_hThread == NULL) usererror("Cannot create console thread!"); DEBUG(driver, 2, "Windows console thread started"); } diff --git a/src/video/sdl_v.cpp b/src/video/sdl_v.cpp index 9872c14cf..869a53ce1 100644 --- a/src/video/sdl_v.cpp +++ b/src/video/sdl_v.cpp @@ -118,7 +118,7 @@ static void GetVideoModes() modes = SDL_CALL SDL_ListModes(NULL, SDL_SWSURFACE + (_fullscreen ? SDL_FULLSCREEN : 0)); if (modes == NULL) - error("sdl: no modes available"); + usererror("sdl: no modes available"); _all_modes = (modes == (void*)-1); @@ -198,7 +198,7 @@ static bool CreateMainSurface(int w, int h) DEBUG(driver, 1, "SDL: using mode %dx%dx%d", w, h, bpp); - if (bpp == 0) error("Can't use a blitter that blits 0 bpp for normal visuals"); + if (bpp == 0) usererror("Can't use a blitter that blits 0 bpp for normal visuals"); /* Give the application an icon */ icon = SDL_CALL SDL_LoadBMP(ICON_DIR PATHSEP "openttd.32.bmp"); diff --git a/src/video/win32_v.cpp b/src/video/win32_v.cpp index f553b9916..19311bb36 100644 --- a/src/video/win32_v.cpp +++ b/src/video/win32_v.cpp @@ -59,7 +59,7 @@ static void MakePalette() } _wnd.gdi_palette = CreatePalette(pal); - if (_wnd.gdi_palette == NULL) error("CreatePalette failed!\n"); + if (_wnd.gdi_palette == NULL) usererror("CreatePalette failed!\n"); } static void UpdatePalette(HDC dc, uint start, uint count) @@ -292,7 +292,7 @@ static bool MakeWindow(bool full_screen) _sntprintf(Windowtitle, sizeof(Windowtitle), _T("OpenTTD %s"), MB_TO_WIDE(_openttd_revision)); _wnd.main_wnd = CreateWindow(_T("OTTD"), Windowtitle, style, x, y, w, h, 0, 0, GetModuleHandle(NULL), 0); - if (_wnd.main_wnd == NULL) error("CreateWindow failed"); + if (_wnd.main_wnd == NULL) usererror("CreateWindow failed"); ShowWindow(_wnd.main_wnd, showstyle); } } @@ -671,7 +671,7 @@ static void RegisterWndClass() }; registered = true; - if (!RegisterClass(&wnd)) error("RegisterClass failed"); + if (!RegisterClass(&wnd)) usererror("RegisterClass failed"); } } @@ -684,7 +684,7 @@ static bool AllocateDibSection(int w, int h) w = max(w, 64); h = max(h, 64); - if (bpp == 0) error("Can't use a blitter that blits 0 bpp for normal visuals"); + if (bpp == 0) usererror("Can't use a blitter that blits 0 bpp for normal visuals"); if (w == _screen.width && h == _screen.height) return false; @@ -707,7 +707,7 @@ static bool AllocateDibSection(int w, int h) dc = GetDC(0); _wnd.dib_sect = CreateDIBSection(dc, bi, DIB_RGB_COLORS, (VOID**)&_wnd.buffer_bits, NULL, 0); - if (_wnd.dib_sect == NULL) error("CreateDIBSection failed"); + if (_wnd.dib_sect == NULL) usererror("CreateDIBSection failed"); ReleaseDC(0, dc); return true; diff --git a/src/win32.cpp b/src/win32.cpp index 5fa7edc82..e2e02d905 100644 --- a/src/win32.cpp +++ b/src/win32.cpp @@ -92,14 +92,14 @@ void SetExceptionString(const char *s, ...) } #endif -void ShowOSErrorBox(const char *buf) +void ShowOSErrorBox(const char *buf, bool system) { MyShowCursor(true); MessageBox(GetActiveWindow(), MB_TO_WIDE(buf), _T("Error!"), MB_ICONSTOP); /* if exception tracker is enabled, we crash here to let the exception handler handle it. */ #if defined(WIN32_EXCEPTION_TRACKER) && !defined(_DEBUG) - if (*buf == '!') { + if (system) { _exception_string = buf; *(byte*)0 = 0; } @@ -961,7 +961,7 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLi #if !defined(WINCE) /* Check if a win9x user started the win32 version */ - if (HasBit(GetVersion(), 31)) error("This version of OpenTTD doesn't run on windows 95/98/ME.\nPlease download the win9x binary and try again."); + if (HasBit(GetVersion(), 31)) usererror("This version of OpenTTD doesn't run on windows 95/98/ME.\nPlease download the win9x binary and try again."); #endif /* For UNICODE we need to convert the commandline to char* _AND_ |