Assert.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. // Copyright 2015 Dolphin Emulator Project
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #pragma once
  4. #include "Common/Common.h"
  5. #include "Common/CommonFuncs.h"
  6. #include "Common/Logging/Log.h"
  7. #include "Common/MsgHandler.h"
  8. #define ASSERT_MSG(_t_, _a_, _fmt_, ...) \
  9. do \
  10. { \
  11. if (!(_a_)) [[unlikely]] \
  12. { \
  13. if (!PanicYesNoFmtAssert(_t_, \
  14. "An error occurred.\n\n" _fmt_ "\n\n" \
  15. " Condition: {}\n File: {}\n Line: {}\n Function: {}\n\n" \
  16. "Ignore and continue?", \
  17. __VA_ARGS__ __VA_OPT__(, ) #_a_, __FILE__, __LINE__, __func__)) \
  18. Crash(); \
  19. } \
  20. } while (0)
  21. #define DEBUG_ASSERT_MSG(_t_, _a_, _fmt_, ...) \
  22. do \
  23. { \
  24. if constexpr (Common::Log::MAX_LOGLEVEL >= Common::Log::LogLevel::LDEBUG) \
  25. ASSERT_MSG(_t_, _a_, _fmt_ __VA_OPT__(, ) __VA_ARGS__); \
  26. } while (0)
  27. #define ASSERT(_a_) \
  28. do \
  29. { \
  30. if (!(_a_)) [[unlikely]] \
  31. { \
  32. if (!PanicYesNoFmt("An error occurred.\n\n" \
  33. " Condition: {}\n File: {}\n Line: {}\n Function: {}\n\n" \
  34. "Ignore and continue?", \
  35. #_a_, __FILE__, __LINE__, __func__)) \
  36. Crash(); \
  37. } \
  38. } while (0)
  39. #define DEBUG_ASSERT(_a_) \
  40. do \
  41. { \
  42. if constexpr (Common::Log::MAX_LOGLEVEL >= Common::Log::LogLevel::LDEBUG) \
  43. ASSERT(_a_); \
  44. } while (0)