2
0

Assert.cpp 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. // Copyright (C) 2009-2018, 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 <cstdlib>
  8. #include <cstdio>
  9. #if ANKI_OS == ANKI_OS_ANDROID
  10. # include <android/log.h>
  11. #endif
  12. namespace anki
  13. {
  14. #if ANKI_EXTRA_CHECKS
  15. void akassert(const char* exprTxt, const char* file, int line, const char* func)
  16. {
  17. # if ANKI_OS == ANKI_OS_ANDROID
  18. __android_log_print(ANDROID_LOG_ERROR, "AnKi", "(%s:%d %s) Assertion failed: %s", file, line, func, exprTxt);
  19. # else
  20. # if ANKI_OS == ANKI_OS_LINUX
  21. if(runningFromATerminal())
  22. fprintf(stderr, "\033[1;31m(%s:%d %s) Assertion failed: %s\033[0m\n", file, line, func, exprTxt);
  23. else
  24. # endif
  25. fprintf(stderr, "(%s:%d %s) Assertion failed: %s\n", file, line, func, exprTxt);
  26. # endif
  27. class BW : public BackTraceWalker
  28. {
  29. public:
  30. BW()
  31. : BackTraceWalker(10)
  32. {
  33. }
  34. U m_c = 0;
  35. void operator()(const char* symbol)
  36. {
  37. printf("%.2u: %s\n", unsigned(m_c++), symbol);
  38. }
  39. };
  40. BW bw;
  41. printf("Backtrace:\n");
  42. bw.exec();
  43. abort();
  44. }
  45. #endif
  46. } // end namespace anki