在kbegine中实现了引擎自带的assert,下面对其进行粗略分析
void myassert(const char * exp, const char * func, const char * file, unsigned int line)
{
DebugHelper::getSingleton().backtrace_msg();
std::string s = (fmt::format("assertion failed: {}, file {}, line {}, at: {}\n", exp, file, line, func));
printf("%s", (std::string("[ASSERT]: ") + s).c_str());
dbghelper.print_msg(s);
//abort 会抛出异常,在debug模式下会被ide捕获,从而起到了触发中断作用,根据中断回溯调用堆栈
abort();
}
//调用该宏会传入当前函数名、函数所在的文件、函数所在的行数,已备在日志中查看定位问题
#define KBE_ASSERT(exp) if(!(exp))myassert(#exp, __FUNCTION__, __FILE__, __LINE__);