summaryrefslogtreecommitdiff
path: root/Source/Core/Common/Assert.h
blob: 5be700f3387da027cb342b90232eae7f035676b6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// Copyright 2015 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.

#pragma once

#include "Common/Common.h"
#include "Common/CommonFuncs.h"
#include "Common/Logging/Log.h"
#include "Common/MsgHandler.h"

#ifdef _WIN32
#define ASSERT_MSG(_t_, _a_, _fmt_, ...)                                                           \
  do                                                                                               \
  {                                                                                                \
    if (!(_a_))                                                                                    \
    {                                                                                              \
      if (!PanicYesNo(_fmt_ "\n\nIgnore and continue?", __VA_ARGS__))                              \
        Crash();                                                                                   \
    }                                                                                              \
  } while (0)

#define DEBUG_ASSERT_MSG(_t_, _a_, _msg_, ...)                                                     \
  do                                                                                               \
  {                                                                                                \
    if (MAX_LOGLEVEL >= LogTypes::LOG_LEVELS::LDEBUG && !(_a_))                                    \
    {                                                                                              \
      ERROR_LOG(_t_, _msg_, __VA_ARGS__);                                                          \
      if (!PanicYesNo(_msg_, __VA_ARGS__))                                                         \
        Crash();                                                                                   \
    }                                                                                              \
  } while (0)
#else
#define ASSERT_MSG(_t_, _a_, _fmt_, ...)                                                           \
  do                                                                                               \
  {                                                                                                \
    if (!(_a_))                                                                                    \
    {                                                                                              \
      if (!PanicYesNo(_fmt_, ##__VA_ARGS__))                                                       \
        Crash();                                                                                   \
    }                                                                                              \
  } while (0)

#define DEBUG_ASSERT_MSG(_t_, _a_, _msg_, ...)                                                     \
  do                                                                                               \
  {                                                                                                \
    if (MAX_LOGLEVEL >= LogTypes::LOG_LEVELS::LDEBUG && !(_a_))                                    \
    {                                                                                              \
      ERROR_LOG(_t_, _msg_, ##__VA_ARGS__);                                                        \
      if (!PanicYesNo(_msg_, ##__VA_ARGS__))                                                       \
        Crash();                                                                                   \
    }                                                                                              \
  } while (0)
#endif

#define ASSERT(_a_)                                                                                \
  do                                                                                               \
  {                                                                                                \
    ASSERT_MSG(MASTER_LOG, _a_,                                                                    \
               _trans("An error occurred.\n\n  Line: %d\n  File: %s\n\nIgnore and continue?"),     \
               __LINE__, __FILE__);                                                                \
  } while (0)

#define DEBUG_ASSERT(_a_)                                                                          \
  do                                                                                               \
  {                                                                                                \
    if (MAX_LOGLEVEL >= LogTypes::LOG_LEVELS::LDEBUG)                                              \
      ASSERT(_a_);                                                                                 \
  } while (0)