From bc283ac60e1cbdcf0c4e5c7f46e34b08b14fbe78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Thu, 13 Mar 2025 15:56:18 +0100 Subject: [PATCH] Add new assert/log facility _dbg_assert_or_log_. Asserts in debug builds, logs in release builds. --- Common/Log.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/Common/Log.h b/Common/Log.h index c10a342f2f..2b2bdc02b2 100644 --- a/Common/Log.h +++ b/Common/Log.h @@ -141,16 +141,35 @@ void SetCleanExitOnAssert(); if (!HandleAssert(__FUNCTION__, __FILENAME__, __LINE__, #_a_, "Assert!\n")) Crash(); \ } +#define _dbg_assert_or_log_(_a_) \ + if (!(_a_)) {\ + if (!HandleAssert(__FUNCTION__, __FILENAME__, __LINE__, #_a_, "Assert!\n")) Crash(); \ + } + #define _dbg_assert_msg_(_a_, ...) \ if (!(_a_)) { \ if (!HandleAssert(__FUNCTION__, __FILENAME__, __LINE__, #_a_, __VA_ARGS__)) Crash(); \ } +#define _dbg_assert_msg_or_log_(_a_, log, ...) \ + if (!(_a_)) { \ + if (!HandleAssert(__FUNCTION__, __FILENAME__, __LINE__, #_a_, __VA_ARGS__)) Crash(); \ + } + #else // not debug #ifndef _dbg_assert_ #define _dbg_assert_(_a_) {} +#define _dbg_assert_or_log_(_a_) \ + if (!(_a_)) { \ + ERROR_LOG(Log::System, "Assert! " ## #_a_); \ + } #define _dbg_assert_msg_(_a_, _desc_, ...) {} +#define _dbg_assert_msg_or_log_(_a_, log, ...) \ + if (!(_a_)) { \ + ERROR_LOG(log, __VA_ARGS__); \ + } + #endif // dbg_assert #endif // MAX_LOGLEVEL DEBUG