Added configurable assert handler function.

This commit is contained in:
Бранимир Караџић
2023-11-13 20:48:34 -08:00
parent d8c3672bce
commit 44fe98c53c
4 changed files with 97 additions and 14 deletions

View File

@@ -113,6 +113,32 @@ namespace bx
/// Unknown source code location.
static constexpr LocationFull kUnknownLocationFull("Unknown?", "Unknown?", 0);
/// Assert handler function.
///
/// @param[in] _location Source code location where function is called.
/// @param[in] _format Printf style format.
/// @param[in] ... Arguments for `_format` specification.
///
/// @returns True if assert should stop code execution, otherwise returns false.
///
typedef bool (*AssertHandlerFn)(const Location& _location, const char* _format, va_list _argList);
/// Set assert handler function.
///
/// @param[in] _assertHandlerFn Pointer to AssertHandlerFn function.
///
void setAssertHandler(AssertHandlerFn _assertHandlerFn);
/// Assert function calls AssertHandlerFn.
///
/// @param[in] _location Source code location where function is called.
/// @param[in] _format Printf style format.
/// @param[in] ... Arguments for `_format` specification.
///
/// @returns True if assert should stop code execution, otherwise returns false.
///
bool assertFunction(const Location& _location, const char* _format, ...);
/// Arithmetic type `Ty` limits.
template<typename Ty, bool SignT = isSigned<Ty>()>
struct LimitsT;

View File

@@ -302,22 +302,22 @@
} \
BX_MACRO_BLOCK_END
#define _BX_ASSERT(_condition, _format, ...) \
BX_MACRO_BLOCK_BEGIN \
if (!BX_IGNORE_C4127(_condition) ) \
{ \
BX_TRACE("ASSERT " _format, ##__VA_ARGS__); \
bx::debugBreak(); \
} \
#define _BX_ASSERT(_condition, _format, ...) \
BX_MACRO_BLOCK_BEGIN \
if (!BX_IGNORE_C4127(_condition) \
&& bx::assertFunction(bx::Location::current(), "ASSERT " #_condition " -> " _format, ##__VA_ARGS__) ) \
{ \
bx::debugBreak(); \
} \
BX_MACRO_BLOCK_END
#define _BX_ASSERT_LOC(_location, _condition, _format, ...) \
BX_MACRO_BLOCK_BEGIN \
if (!BX_IGNORE_C4127(_condition) ) \
{ \
_BX_TRACE_LOC(_location, "ASSERT " _format, ##__VA_ARGS__); \
bx::debugBreak(); \
} \
#define _BX_ASSERT_LOC(_location, _condition, _format, ...) \
BX_MACRO_BLOCK_BEGIN \
if (!BX_IGNORE_C4127(_condition) \
&& bx::assertFunction(_location, "ASSERT " #_condition " -> " _format, ##__VA_ARGS__) ) \
{ \
bx::debugBreak(); \
} \
BX_MACRO_BLOCK_END
#define _BX_WARN_LOC(_location, _condition, _format, ...) \