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

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