impr: Properly print asserts

This commit is contained in:
WerWolv 2023-07-23 23:39:00 +02:00
parent ffdaf0d16e
commit 8b3cd2d76d
2 changed files with 16 additions and 0 deletions

View File

@ -14,10 +14,16 @@
#pragma once
#include <assert.h>
//---- 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.

View File

@ -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
}
}
}