Add support for verbose asserts.
(cherry picked from commit 48e4c35fdc
)
This commit is contained in:
@@ -123,6 +123,25 @@ void CDECL error(const char *s, ...)
|
|||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CDECL assert_msg_error(int line, const char *file, const char *expr, const char *str, ...)
|
||||||
|
{
|
||||||
|
va_list va;
|
||||||
|
char buf[2048];
|
||||||
|
|
||||||
|
char *b = buf;
|
||||||
|
b += seprintf(b, lastof(buf), "Assertion failed at line %i of %s: %s\n\t", line, file, expr);
|
||||||
|
|
||||||
|
va_start(va, str);
|
||||||
|
vseprintf(b, lastof(buf), str, va);
|
||||||
|
va_end(va);
|
||||||
|
|
||||||
|
ShowOSErrorBox(buf, true);
|
||||||
|
|
||||||
|
/* Set the error message for the crash log and then invoke it. */
|
||||||
|
CrashLog::SetErrorMessage(buf);
|
||||||
|
abort();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Shows some information on the console/a popup box depending on the OS.
|
* Shows some information on the console/a popup box depending on the OS.
|
||||||
* @param str the text to show.
|
* @param str the text to show.
|
||||||
|
@@ -433,6 +433,7 @@ assert_compile(SIZE_MAX >= UINT32_MAX);
|
|||||||
|
|
||||||
void NORETURN CDECL usererror(const char *str, ...) WARN_FORMAT(1, 2);
|
void NORETURN CDECL usererror(const char *str, ...) WARN_FORMAT(1, 2);
|
||||||
void NORETURN CDECL error(const char *str, ...) WARN_FORMAT(1, 2);
|
void NORETURN CDECL error(const char *str, ...) WARN_FORMAT(1, 2);
|
||||||
|
void NORETURN CDECL assert_msg_error(int line, const char *file, const char *expr, const char *str, ...) WARN_FORMAT(4, 5);
|
||||||
#define NOT_REACHED() error("NOT_REACHED triggered at line %i of %s", __LINE__, __FILE__)
|
#define NOT_REACHED() error("NOT_REACHED triggered at line %i of %s", __LINE__, __FILE__)
|
||||||
|
|
||||||
/* For non-debug builds with assertions enabled use the special assertion handler:
|
/* For non-debug builds with assertions enabled use the special assertion handler:
|
||||||
@@ -447,6 +448,9 @@ void NORETURN CDECL error(const char *str, ...) WARN_FORMAT(1, 2);
|
|||||||
/* Asserts are enabled if NDEBUG isn't defined, or if we are using MSVC and WITH_ASSERT is defined. */
|
/* Asserts are enabled if NDEBUG isn't defined, or if we are using MSVC and WITH_ASSERT is defined. */
|
||||||
#if !defined(NDEBUG) || (defined(_MSC_VER) && defined(WITH_ASSERT))
|
#if !defined(NDEBUG) || (defined(_MSC_VER) && defined(WITH_ASSERT))
|
||||||
#define OTTD_ASSERT
|
#define OTTD_ASSERT
|
||||||
|
#define assert_msg(expression, ...) if (!(expression)) assert_msg_error(__LINE__, __FILE__, #expression, __VA_ARGS__);
|
||||||
|
#else
|
||||||
|
#define assert_msg(expression, ...)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(MORPHOS) || defined(__NDS__) || defined(__DJGPP__)
|
#if defined(MORPHOS) || defined(__NDS__) || defined(__DJGPP__)
|
||||||
|
Reference in New Issue
Block a user