Assert: Add more assert macros for using a simple string as the extra text

mapgen-water-desert-removal-circular
Jonathan G Rennison 5 months ago
parent 61db988a4a
commit 5e2ac22ef5

@ -227,13 +227,19 @@ void CDECL assert_msg_error(int line, const char *file, const char *expr, const
vseprintf(b, lastof(buf), str, va);
va_end(va);
if (VideoDriver::GetInstance() == nullptr || VideoDriver::GetInstance()->HasGUI()) {
ShowOSErrorBox(buf, true);
}
fatalerror_common(buf);
}
/* Set the error message for the crash log and then invoke it. */
CrashLog::SetErrorMessage(buf);
DoOSAbort();
void assert_str_error(int line, const char *file, const char *expr, const char *str)
{
char buf[2048];
seprintf(buf, lastof(buf), "Assertion failed at line %i of %s: %s\n%s", line, file, expr, str);
fatalerror_common(buf);
}
void assert_str_error(int line, const char *file, const char *expr, const std::string &str)
{
assert_str_error(line, file, expr, str.c_str());
}
const char *assert_tile_info(uint32_t tile) {

@ -433,6 +433,8 @@ typedef uint64_t unaligned_uint64;
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 assert_msg_error(int line, const char *file, const char *expr, const char *extra, const char *str, ...) WARN_FORMAT(5, 6);
void NORETURN assert_str_error(int line, const char *file, const char *expr, const char *str);
void NORETURN assert_str_error(int line, const char *file, const char *expr, const std::string &str);
const char *assert_tile_info(uint32_t tile);
#define NOT_REACHED() error("NOT_REACHED triggered at line %i of %s", __LINE__, __FILE__)
@ -443,12 +445,14 @@ const char *assert_tile_info(uint32_t tile);
# define assert_msg(expression, ...) if (unlikely(!(expression))) assert_msg_error(__LINE__, __FILE__, #expression, nullptr, __VA_ARGS__);
# define assert_msg_tile(expression, tile, ...) if (unlikely(!(expression))) assert_msg_error(__LINE__, __FILE__, #expression, assert_tile_info(tile), __VA_ARGS__);
# define assert_tile(expression, tile) if (unlikely(!(expression))) error("Assertion failed at line %i of %s: %s\n\t%s", __LINE__, __FILE__, #expression, assert_tile_info(tile));
# define assert_str(expression, str) if (unlikely(!(expression))) assert_str_error(__LINE__, __FILE__, #expression, str);
#else
# undef assert
# define assert(expression)
# define assert_msg(expression, ...)
# define assert_msg_tile(expression, tile, ...)
# define assert_tile(expression, tile)
# define assert_str(expression, str)
#endif
#if (!defined(NDEBUG) || defined(WITH_ASSERT)) && !defined(FEWER_ASSERTS)
# define WITH_FULL_ASSERTS

Loading…
Cancel
Save