Assert.cpp 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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", "Assertion failed: %s (%s:%d %s)", exprTxt, file, line, func);
  20. # else
  21. # if ANKI_OS_LINUX
  22. if(runningFromATerminal())
  23. {
  24. fprintf(stderr, "\033[1;31mAssertion failed: %s (%s:%d %s)\033[0m\n", exprTxt, file, line, func);
  25. }
  26. else
  27. # endif
  28. {
  29. fprintf(stderr, "Assertion failed: %s (%s:%d %s)\n", exprTxt, file, line, func);
  30. }
  31. # endif
  32. printf("Backtrace:\n");
  33. U32 count = 0;
  34. backtrace(HeapAllocator<U8>(allocAligned, nullptr),
  35. [&count](CString symbol) { printf("%.2u: %s\n", count++, symbol.cstr()); });
  36. ANKI_DEBUG_BREAK();
  37. }
  38. #endif
  39. } // end namespace anki