From 8b3cd2d76dc2317759bad61c7fa7071b7ac53431 Mon Sep 17 00:00:00 2001 From: WerWolv Date: Sun, 23 Jul 2023 23:39:00 +0200 Subject: [PATCH] impr: Properly print asserts --- lib/external/imgui/include/imconfig.h | 6 ++++++ lib/libimhex/source/helpers/logger.cpp | 10 ++++++++++ 2 files changed, 16 insertions(+) diff --git a/lib/external/imgui/include/imconfig.h b/lib/external/imgui/include/imconfig.h index 876cf32f7..9039755b8 100644 --- a/lib/external/imgui/include/imconfig.h +++ b/lib/external/imgui/include/imconfig.h @@ -14,10 +14,16 @@ #pragma once +#include + //---- Define assertion handler. Defaults to calling assert(). // If your macro uses multiple statements, make sure is enclosed in a 'do { .. } while (0)' block so it can be used as a single statement. //#define IM_ASSERT(_EXPR) MyAssert(_EXPR) //#define IM_ASSERT(_EXPR) ((void)(_EXPR)) // Disable asserts +namespace hex::log::impl { + void assertionHandler(bool expr, const char* expr_str, const char* file, int line); +} +#define IM_ASSERT(_EXPR) hex::log::impl::assertionHandler(_EXPR, #_EXPR, __FILE__, __LINE__) //---- Define attributes of all API symbols declarations, e.g. for DLL under Windows // Using Dear ImGui via a shared library is not recommended, because of function call overhead and because we don't guarantee backward nor forward ABI compatibility. diff --git a/lib/libimhex/source/helpers/logger.cpp b/lib/libimhex/source/helpers/logger.cpp index 99ab66b67..e1f565727 100644 --- a/lib/libimhex/source/helpers/logger.cpp +++ b/lib/libimhex/source/helpers/logger.cpp @@ -42,4 +42,14 @@ namespace hex::log::impl { return logEntries; } + void assertionHandler(bool expr, const char* expr_str, const char* file, int line) { + if (!expr) { + log::error("Assertion failed: {} at {}:{}", expr_str, file, line); + + #if defined (DEBUG) + std::abort(); + #endif + } + } + } \ No newline at end of file