diff --git a/src/openttd.cpp b/src/openttd.cpp index 0ec662e14a..efa36b0716 100644 --- a/src/openttd.cpp +++ b/src/openttd.cpp @@ -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) { diff --git a/src/stdafx.h b/src/stdafx.h index 2bf48e5330..5104c34108 100644 --- a/src/stdafx.h +++ b/src/stdafx.h @@ -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