mirror of https://github.com/WerWolv/ImHex.git
impr: Properly print asserts
This commit is contained in:
parent
ffdaf0d16e
commit
8b3cd2d76d
|
@ -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.
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue