Assert.cpp 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. // Copyright (C) 2009-2020, Panagiotis Christopoulos Charitos and contributors.
  2. // All rights reserved.
  3. // Code licensed under the BSD License.
  4. // http://www.anki3d.org/LICENSE
  5. #include <anki/util/Assert.h>
  6. #include <anki/util/System.h>
  7. #include <anki/util/Functions.h>
  8. #include <cstdlib>
  9. #include <cstdio>
  10. #if ANKI_OS_ANDROID
  11. # include <android/log.h>
  12. #endif
  13. namespace anki
  14. {
  15. #if ANKI_EXTRA_CHECKS
  16. void akassert(const char* exprTxt, const char* file, int line, const char* func)
  17. {
  18. # if ANKI_OS_ANDROID
  19. __android_log_print(ANDROID_LOG_ERROR, "AnKi", "(%s:%d %s) Assertion failed: %s", file, line, func, exprTxt);
  20. # else
  21. # if ANKI_OS_LINUX
  22. if(runningFromATerminal())
  23. fprintf(stderr, "\033[1;31m(%s:%d %s) Assertion failed: %s\033[0m\n", file, line, func, exprTxt);
  24. else
  25. # endif
  26. fprintf(stderr, "(%s:%d %s) Assertion failed: %s\n", file, line, func, exprTxt);
  27. # endif
  28. class BW : public BackTraceWalker
  29. {
  30. public:
  31. BW()
  32. : BackTraceWalker(10)
  33. {
  34. }
  35. U m_c = 0;
  36. void operator()(const char* symbol)
  37. {
  38. printf("%.2u: %s\n", unsigned(m_c++), symbol);
  39. }
  40. };
  41. BW bw;
  42. printf("Backtrace:\n");
  43. bw.exec();
  44. ANKI_DEBUG_BREAK();
  45. }
  46. #endif
  47. } // end namespace anki