diff --git a/Sources/OvDebug/include/OvDebug/Assertion.h b/Sources/OvDebug/include/OvDebug/Assertion.h index 615a1201..92c554f3 100644 --- a/Sources/OvDebug/include/OvDebug/Assertion.h +++ b/Sources/OvDebug/include/OvDebug/Assertion.h @@ -6,30 +6,23 @@ #pragma once +#include #include - -#define OVASSERT(condition, message) OvDebug::Assertion::Assert(condition, message) +#ifdef NDEBUG +#define OVASSERT(condition, message) static_cast(0) +#else +#define OVASSERT(condition, message) \ + static_cast(condition) ? \ + static_cast(0) : \ + OvDebug::_Assert(#condition, message, std::source_location::current()); +#endif namespace OvDebug { - /** - * Wrapper for C++ assert - */ - class Assertion - { - public: - - /** - * Disabled constructor - */ - Assertion() = delete; - - /** - * C++ assertion wrapped call - * @param p_condition - * @param p_message - */ - static void Assert(bool p_condition, const std::string& p_message = ""); - }; + void _Assert( + const char* p_expression, + const std::string_view p_message, + const std::source_location& p_location + ); } \ No newline at end of file diff --git a/Sources/OvDebug/src/OvDebug/Assertion.cpp b/Sources/OvDebug/src/OvDebug/Assertion.cpp index a41164b3..4364f04e 100644 --- a/Sources/OvDebug/src/OvDebug/Assertion.cpp +++ b/Sources/OvDebug/src/OvDebug/Assertion.cpp @@ -4,11 +4,28 @@ * @licence: MIT */ -#include "OvDebug/Assertion.h" +#include +#include #include +#include -void OvDebug::Assertion::Assert(bool p_condition, const std::string& p_message) +#if defined(_MSC_VER) +# define OV_DEBUG_BREAK() __debugbreak() +#elif defined(__clang__) || defined(__GNUC__) +# define OV_DEBUG_BREAK() __builtin_trap() +#else +# define OV_DEBUG_BREAK() std::abort() +#endif + +void OvDebug::_Assert(const char* p_expression, const std::string_view p_message, const std::source_location& p_location) { - assert(p_condition && p_message.c_str()); -} + OVLOG_ERROR(std::format( + "Assertion failed: {}\n" + " Expression: {}\n" + " Function: {}\n" + " Location: {}:{}", + p_message, p_expression, p_location.function_name(), + p_location.file_name(), p_location.line())); + OV_DEBUG_BREAK(); +} \ No newline at end of file