From b60a1326bf3ea9b9e0235cf18cdcd964c758a8bf Mon Sep 17 00:00:00 2001 From: glx Date: Thu, 5 Jun 2008 20:54:52 +0000 Subject: (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(). --- src/openttd.cpp | 42 +++++++++++++++++++++++++++++++----------- 1 file changed, 31 insertions(+), 11 deletions(-) (limited to 'src/openttd.cpp') 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; -- cgit v1.2.3-54-g00ecf