Assert.cpp 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // Copyright (C) 2009-2022, 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. #if ANKI_EXTRA_CHECKS
  15. void akassert(const char* exprTxt, const char* file, int line, const char* func)
  16. {
  17. # if ANKI_OS_ANDROID
  18. __android_log_print(ANDROID_LOG_ERROR, "AnKi", "Assertion failed: %s (%s:%d %s)", exprTxt, file, line, func);
  19. # else
  20. # if ANKI_OS_LINUX
  21. if(runningFromATerminal())
  22. {
  23. fprintf(stderr, "\033[1;31mAssertion failed: %s (%s:%d %s)\033[0m\n", exprTxt, file, line, func);
  24. }
  25. else
  26. # endif
  27. {
  28. fprintf(stderr, "Assertion failed: %s (%s:%d %s)\n", exprTxt, file, line, func);
  29. }
  30. # endif
  31. printf("Backtrace:\n");
  32. U32 count = 0;
  33. HeapMemoryPool pool(allocAligned, nullptr);
  34. backtrace(pool, [&count](CString symbol) {
  35. printf("%.2u: %s\n", count++, symbol.cstr());
  36. });
  37. ANKI_DEBUG_BREAK();
  38. }
  39. #endif
  40. } // end namespace anki