Debug: Provide UserError, FatalError fmt macros
This commit is contained in:
@@ -21,4 +21,10 @@
|
|||||||
*/
|
*/
|
||||||
#define Debug(name, level, format_string, ...) if ((level) == 0 || _debug_ ## name ## _level >= (level)) debug_print(#name, fmt::format(FMT_STRING(format_string), ## __VA_ARGS__).c_str())
|
#define Debug(name, level, format_string, ...) if ((level) == 0 || _debug_ ## name ## _level >= (level)) debug_print(#name, fmt::format(FMT_STRING(format_string), ## __VA_ARGS__).c_str())
|
||||||
|
|
||||||
|
void NORETURN usererror_str(const char *msg);
|
||||||
|
void NORETURN fatalerror_str(const char *msg);
|
||||||
|
|
||||||
|
#define UserError(format_string, ...) usererror_str(fmt::format(FMT_STRING(format_string), ## __VA_ARGS__).c_str())
|
||||||
|
#define FatalError(format_string, ...) fatalerror_str(fmt::format(FMT_STRING(format_string), ## __VA_ARGS__).c_str())
|
||||||
|
|
||||||
#endif /* DEBUG_FMT_H */
|
#endif /* DEBUG_FMT_H */
|
||||||
|
@@ -139,6 +139,22 @@ std::mutex _music_driver_mutex;
|
|||||||
static std::string _music_driver_params;
|
static std::string _music_driver_params;
|
||||||
static std::atomic<bool> _music_inited;
|
static std::atomic<bool> _music_inited;
|
||||||
|
|
||||||
|
void NORETURN usererror_str(const char *msg)
|
||||||
|
{
|
||||||
|
ShowOSErrorBox(msg, false);
|
||||||
|
if (VideoDriver::GetInstance() != nullptr) VideoDriver::GetInstance()->Stop();
|
||||||
|
|
||||||
|
#ifdef __EMSCRIPTEN__
|
||||||
|
emscripten_exit_pointerlock();
|
||||||
|
/* In effect, the game ends here. As emscripten_set_main_loop() caused
|
||||||
|
* the stack to be unwound, the code after MainLoop() in
|
||||||
|
* openttd_main() is never executed. */
|
||||||
|
EM_ASM(if (window["openttd_abort"]) openttd_abort());
|
||||||
|
#endif
|
||||||
|
|
||||||
|
_exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Error handling for fatal user errors.
|
* Error handling for fatal user errors.
|
||||||
* @param s the string to print.
|
* @param s the string to print.
|
||||||
@@ -153,18 +169,18 @@ void CDECL usererror(const char *s, ...)
|
|||||||
vseprintf(buf, lastof(buf), s, va);
|
vseprintf(buf, lastof(buf), s, va);
|
||||||
va_end(va);
|
va_end(va);
|
||||||
|
|
||||||
ShowOSErrorBox(buf, false);
|
usererror_str(buf);
|
||||||
if (VideoDriver::GetInstance() != nullptr) VideoDriver::GetInstance()->Stop();
|
}
|
||||||
|
|
||||||
#ifdef __EMSCRIPTEN__
|
static void NORETURN fatalerror_common(const char *msg)
|
||||||
emscripten_exit_pointerlock();
|
{
|
||||||
/* In effect, the game ends here. As emscripten_set_main_loop() caused
|
if (VideoDriver::GetInstance() == nullptr || VideoDriver::GetInstance()->HasGUI()) {
|
||||||
* the stack to be unwound, the code after MainLoop() in
|
ShowOSErrorBox(msg, true);
|
||||||
* openttd_main() is never executed. */
|
}
|
||||||
EM_ASM(if (window["openttd_abort"]) openttd_abort());
|
|
||||||
#endif
|
|
||||||
|
|
||||||
_exit(1);
|
/* Set the error message for the crash log and then invoke it. */
|
||||||
|
CrashLog::SetErrorMessage(msg);
|
||||||
|
DoOSAbort();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -183,13 +199,14 @@ void CDECL error(const char *s, ...)
|
|||||||
vseprintf(buf, lastof(buf), s, va);
|
vseprintf(buf, lastof(buf), s, va);
|
||||||
va_end(va);
|
va_end(va);
|
||||||
|
|
||||||
if (VideoDriver::GetInstance() == nullptr || VideoDriver::GetInstance()->HasGUI()) {
|
fatalerror_common(buf);
|
||||||
ShowOSErrorBox(buf, true);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/* Set the error message for the crash log and then invoke it. */
|
void fatalerror_str(const char *msg)
|
||||||
CrashLog::SetErrorMessage(buf);
|
{
|
||||||
DoOSAbort();
|
if (CrashLog::HaveAlreadyCrashed()) DoOSAbort();
|
||||||
|
|
||||||
|
fatalerror_common(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CDECL assert_msg_error(int line, const char *file, const char *expr, const char *extra, const char *str, ...)
|
void CDECL assert_msg_error(int line, const char *file, const char *expr, const char *extra, const char *str, ...)
|
||||||
|
Reference in New Issue
Block a user