Assert.cpp 979 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #include "anki/util/Assert.h"
  2. #include "anki/util/System.h"
  3. #include <cstdlib>
  4. #include <iostream>
  5. #if ANKI_OS == ANKI_OS_ANDROID
  6. # include <android/log.h>
  7. #endif
  8. namespace anki {
  9. #if ANKI_DEBUG
  10. //==============================================================================
  11. void akassert(bool expr, const char* exprTxt, const char* file, int line,
  12. const char* func)
  13. {
  14. if(!expr)
  15. {
  16. #if ANKI_OS == ANKI_OS_LINUX
  17. std::cerr << "\033[1;31m(" << file << ":" << line << " "
  18. << func << ") " << "Assertion failed: " << exprTxt << "\033[0m"
  19. << std::endl;
  20. #elif ANKI_OS == ANKI_OS_ANDROID
  21. __android_log_print(ANDROID_LOG_ERROR, "AnKi"
  22. "(%s:%d %s) Assertion failed: %s", file, line,
  23. func, exprTxt);
  24. #else
  25. std::cerr << "(" << file << ":" << line << " "
  26. << func << ") " << "Assertion failed: " << exprTxt
  27. << std::endl;
  28. #endif
  29. #if ANKI_CPU_ARCH == ANKI_CPU_ARCH_INTEL
  30. asm("int $3");
  31. #endif
  32. printBacktrace();
  33. abort();
  34. }
  35. }
  36. #endif
  37. } // end namespace anki