mirror of
https://github.com/bkaradzic/bx.git
synced 2026-02-17 20:52:37 +01:00
Added configurable assert handler function.
This commit is contained in:
41
src/bx.cpp
41
src/bx.cpp
@@ -22,6 +22,47 @@ namespace bx
|
||||
return LocationFull(_function, _filePath, _line);
|
||||
}
|
||||
|
||||
static bool defaultAssertHandler(const Location& _location, const char* _format, va_list _argList)
|
||||
{
|
||||
char temp[8192];
|
||||
int32_t pos = 0;
|
||||
|
||||
pos += snprintf(&temp[pos], max(0, sizeof(temp)-pos), "%s(%d): "
|
||||
, _location.filePath
|
||||
, _location.line
|
||||
);
|
||||
pos += vsnprintf(&temp[pos], max(0, sizeof(temp)-pos), _format, _argList);
|
||||
pos += snprintf(&temp[pos], max(0, sizeof(temp)-pos), "\n");
|
||||
debugOutput(temp);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static AssertHandlerFn s_assertHandler = defaultAssertHandler;
|
||||
|
||||
void setAssertHandler(AssertHandlerFn _assertHandlerFn)
|
||||
{
|
||||
BX_WARN(defaultAssertHandler == s_assertHandler, "Assert handler is already set.");
|
||||
|
||||
if (defaultAssertHandler == s_assertHandler)
|
||||
{
|
||||
s_assertHandler = NULL == _assertHandlerFn
|
||||
? defaultAssertHandler
|
||||
: _assertHandlerFn
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
bool assertFunction(const Location& _location, const char* _format, ...)
|
||||
{
|
||||
va_list argList;
|
||||
va_start(argList, _format);
|
||||
const bool result = s_assertHandler(_location, _format, argList);
|
||||
va_end(argList);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void swap(void* _a, void* _b, size_t _numBytes)
|
||||
{
|
||||
uint8_t* lhs = (uint8_t*)_a;
|
||||
|
||||
Reference in New Issue
Block a user