lzham_assert.cpp 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. // File: lzham_assert.cpp
  2. // See Copyright Notice and license at the end of include/lzham.h
  3. #include "lzham_core.h"
  4. static bool g_fail_exceptions;
  5. static bool g_exit_on_failure = true;
  6. void lzham_enable_fail_exceptions(bool enabled)
  7. {
  8. g_fail_exceptions = enabled;
  9. }
  10. void lzham_assert(const char* pExp, const char* pFile, unsigned line)
  11. {
  12. char buf[512];
  13. sprintf_s(buf, sizeof(buf), "%s(%u): Assertion failed: \"%s\"\n", pFile, line, pExp);
  14. lzham_output_debug_string(buf);
  15. //printf("%s", buf);
  16. if (lzham_is_debugger_present())
  17. lzham_debug_break();
  18. }
  19. void lzham_fail(const char* pExp, const char* pFile, unsigned line)
  20. {
  21. char buf[512];
  22. sprintf_s(buf, sizeof(buf), "%s(%u): Failure: \"%s\"\n", pFile, line, pExp);
  23. lzham_output_debug_string(buf);
  24. //printf("%s", buf);
  25. if (lzham_is_debugger_present())
  26. lzham_debug_break();
  27. #if LZHAM_USE_WIN32_API
  28. if (g_fail_exceptions)
  29. RaiseException(LZHAM_FAIL_EXCEPTION_CODE, 0, 0, NULL);
  30. else
  31. #endif
  32. if (g_exit_on_failure)
  33. exit(EXIT_FAILURE);
  34. }
  35. void lzham_trace(const char* pFmt, va_list args)
  36. {
  37. /*if (lzham_is_debugger_present()) ESENTHEL CHANGED
  38. {
  39. char buf[512];
  40. vsprintf_s(buf, sizeof(buf), pFmt, args);
  41. lzham_output_debug_string(buf);
  42. }*/
  43. };
  44. void lzham_trace(const char* pFmt, ...)
  45. {
  46. va_list args;
  47. va_start(args, pFmt);
  48. lzham_trace(pFmt, args);
  49. va_end(args);
  50. };