Assert.cpp 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. // Copyright (C) 2009-2021, 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. {
  24. fprintf(stderr, "\033[1;31m(%s:%d %s) Assertion failed: %s\033[0m\n", file, line, func, exprTxt);
  25. }
  26. else
  27. # endif
  28. {
  29. fprintf(stderr, "(%s:%d %s) Assertion failed: %s\n", file, line, func, exprTxt);
  30. }
  31. # endif
  32. class BW : public BackTraceWalker
  33. {
  34. public:
  35. U32 m_c = 0;
  36. void operator()(const char* symbol)
  37. {
  38. printf("%.2u: %s\n", m_c++, symbol);
  39. }
  40. };
  41. BW bw;
  42. printf("Backtrace:\n");
  43. getBacktrace(bw);
  44. ANKI_DEBUG_BREAK();
  45. }
  46. #endif
  47. } // end namespace anki