git.s-ol.nu forks/DiligentCore / fef3fe4
Updated handling of fatal errors assiduous 3 years ago
3 changed file(s) with 61 addition(s) and 46 deletion(s). Raw diff Collapse all Expand all
121121 #include "RenderDevice.h"
122122 #include "BaseInterfacesGL.h"
123123
124 #define CHECK_GL_ERROR(...) \
125 do \
126 { \
127 auto err = glGetError(); \
128 if (err != GL_NO_ERROR) \
129 { \
130 LogError<false>(__FUNCTION__, __FILE__, __LINE__, __VA_ARGS__, "\nGL Error Code: ", err); \
131 UNEXPECTED("Error"); \
132 } \
124 #define CHECK_GL_ERROR(...) \
125 do \
126 { \
127 auto err = glGetError(); \
128 if (err != GL_NO_ERROR) \
129 { \
130 LogError<false>(/*IsFatal=*/false, __FUNCTION__, __FILE__, __LINE__, __VA_ARGS__, "\nGL Error Code: ", err); \
131 UNEXPECTED("Error"); \
132 } \
133133 } while (false)
134134
135 #define CHECK_GL_ERROR_AND_THROW(...) \
136 do \
137 { \
138 auto err = glGetError(); \
139 if (err != GL_NO_ERROR) \
140 LogError<true>(__FUNCTION__, __FILE__, __LINE__, __VA_ARGS__, "\nGL Error Code: ", err); \
135 #define CHECK_GL_ERROR_AND_THROW(...) \
136 do \
137 { \
138 auto err = glGetError(); \
139 if (err != GL_NO_ERROR) \
140 LogError<true>(/*IsFatal=*/false, __FUNCTION__, __FILE__, __LINE__, __VA_ARGS__, "\nGL Error Code: ", err); \
141141 } while (false)
142142
143143 #ifdef DEVELOPMENT
3030 #include "DebugUtilities.h"
3131 #include "VulkanUtilities/VulkanDebug.h"
3232
33 #define CHECK_VK_ERROR(err, ...) \
34 { \
35 if (err < 0) \
36 { \
37 Diligent::LogError<false>(__FUNCTION__, __FILE__, __LINE__, __VA_ARGS__, "\nVK Error: ", VulkanUtilities::VkResultToString(err)); \
38 UNEXPECTED("Error"); \
39 } \
33 #define CHECK_VK_ERROR(err, ...) \
34 { \
35 if (err < 0) \
36 { \
37 Diligent::LogError<false>(/*IsFatal=*/false, __FUNCTION__, __FILE__, __LINE__, __VA_ARGS__, "\nVK Error: ", VulkanUtilities::VkResultToString(err)); \
38 UNEXPECTED("Error"); \
39 } \
4040 }
4141
42 #define CHECK_VK_ERROR_AND_THROW(err, ...) \
43 { \
44 if (err < 0) \
45 Diligent::LogError<true>(__FUNCTION__, __FILE__, __LINE__, __VA_ARGS__, "\nVK Error Code: ", VulkanUtilities::VkResultToString(err)); \
42 #define CHECK_VK_ERROR_AND_THROW(err, ...) \
43 { \
44 if (err < 0) \
45 Diligent::LogError<true>(/*IsFatal=*/false, __FUNCTION__, __FILE__, __LINE__, __VA_ARGS__, "\nVK Error Code: ", VulkanUtilities::VkResultToString(err)); \
4646 }
4848 }
4949
5050 template <bool bThrowException, typename... ArgsType>
51 void LogError(const char* Function, const char* FullFilePath, int Line, const ArgsType&... Args)
51 void LogError(bool IsFatal, const char* Function, const char* FullFilePath, int Line, const ArgsType&... Args)
5252 {
5353 std::string FileName(FullFilePath);
5454
5858 auto Msg = FormatString(Args...);
5959 if (DebugMessageCallback != nullptr)
6060 {
61 DebugMessageCallback(bThrowException ? DebugMessageSeverity::FatalError : DebugMessageSeverity::Error, Msg.c_str(), Function, FileName.c_str(), Line);
61 DebugMessageCallback(IsFatal ? DebugMessageSeverity::FatalError : DebugMessageSeverity::Error, Msg.c_str(), Function, FileName.c_str(), Line);
6262 }
6363 else
6464 {
6565 // No callback set - output to cerr
66 std::cerr << "Diligent Engine: " << (bThrowException ? "Fatal Error" : "Error") << " in " << Function << "() (" << FileName << ", " << Line << "): " << Msg << '\n';
66 std::cerr << "Diligent Engine: " << (IsFatal ? "Fatal Error" : "Error") << " in " << Function << "() (" << FileName << ", " << Line << "): " << Msg << '\n';
6767 }
6868 ThrowIf<bThrowException>(std::move(Msg));
6969 }
7272
7373
7474
75 #define LOG_ERROR(...) \
76 do \
77 { \
78 Diligent::LogError<false>(__FUNCTION__, __FILE__, __LINE__, ##__VA_ARGS__); \
75 #define LOG_ERROR(...) \
76 do \
77 { \
78 Diligent::LogError<false>(/*IsFatal=*/false, __FUNCTION__, __FILE__, __LINE__, ##__VA_ARGS__); \
7979 } while (false)
8080
81
82 #define LOG_FATAL_ERROR(...) \
83 do \
84 { \
85 Diligent::LogError<false>(/*IsFatal=*/true, __FUNCTION__, __FILE__, __LINE__, ##__VA_ARGS__); \
86 } while (false)
8187
8288 #define LOG_ERROR_ONCE(...) \
8389 do \
9197 } while (false)
9298
9399
94 #define LOG_ERROR_AND_THROW(...) \
95 do \
96 { \
97 Diligent::LogError<true>(__FUNCTION__, __FILE__, __LINE__, ##__VA_ARGS__); \
100 #define LOG_ERROR_AND_THROW(...) \
101 do \
102 { \
103 Diligent::LogError<true>(/*IsFatal=*/false, __FUNCTION__, __FILE__, __LINE__, ##__VA_ARGS__); \
104 } while (false)
105
106 #define LOG_FATAL_ERROR_AND_THROW(...) \
107 do \
108 { \
109 Diligent::LogError<true>(/*IsFatal=*/true, __FUNCTION__, __FILE__, __LINE__, ##__VA_ARGS__); \
98110 } while (false)
99111
100112
105117 if (Diligent::DebugMessageCallback != nullptr) Diligent::DebugMessageCallback(Severity, _msg.c_str(), nullptr, nullptr, 0); \
106118 } while (false)
107119
108 #define LOG_ERROR_MESSAGE(...) LOG_DEBUG_MESSAGE(Diligent::DebugMessageSeverity::Error, ##__VA_ARGS__)
109 #define LOG_WARNING_MESSAGE(...) LOG_DEBUG_MESSAGE(Diligent::DebugMessageSeverity::Warning, ##__VA_ARGS__)
110 #define LOG_INFO_MESSAGE(...) LOG_DEBUG_MESSAGE(Diligent::DebugMessageSeverity::Info, ##__VA_ARGS__)
120 #define LOG_FATAL_ERROR_MESSAGE(...) LOG_DEBUG_MESSAGE(Diligent::DebugMessageSeverity::FatalError, ##__VA_ARGS__)
121 #define LOG_ERROR_MESSAGE(...) LOG_DEBUG_MESSAGE(Diligent::DebugMessageSeverity::Error, ##__VA_ARGS__)
122 #define LOG_WARNING_MESSAGE(...) LOG_DEBUG_MESSAGE(Diligent::DebugMessageSeverity::Warning, ##__VA_ARGS__)
123 #define LOG_INFO_MESSAGE(...) LOG_DEBUG_MESSAGE(Diligent::DebugMessageSeverity::Info, ##__VA_ARGS__)
111124
112125
113126 #define LOG_DEBUG_MESSAGE_ONCE(Severity, ...) \
121134 } \
122135 } while (false)
123136
124 #define LOG_ERROR_MESSAGE_ONCE(...) LOG_DEBUG_MESSAGE_ONCE(Diligent::DebugMessageSeverity::Error, ##__VA_ARGS__)
125 #define LOG_WARNING_MESSAGE_ONCE(...) LOG_DEBUG_MESSAGE_ONCE(Diligent::DebugMessageSeverity::Warning, ##__VA_ARGS__)
126 #define LOG_INFO_MESSAGE_ONCE(...) LOG_DEBUG_MESSAGE_ONCE(Diligent::DebugMessageSeverity::Info, ##__VA_ARGS__)
137 #define LOG_FATAL_ERROR_MESSAGE_ONCE(...) LOG_DEBUG_MESSAGE_ONCE(Diligent::DebugMessageSeverity::FatalError, ##__VA_ARGS__)
138 #define LOG_ERROR_MESSAGE_ONCE(...) LOG_DEBUG_MESSAGE_ONCE(Diligent::DebugMessageSeverity::Error, ##__VA_ARGS__)
139 #define LOG_WARNING_MESSAGE_ONCE(...) LOG_DEBUG_MESSAGE_ONCE(Diligent::DebugMessageSeverity::Warning, ##__VA_ARGS__)
140 #define LOG_INFO_MESSAGE_ONCE(...) LOG_DEBUG_MESSAGE_ONCE(Diligent::DebugMessageSeverity::Info, ##__VA_ARGS__)
127141
128142
129143 #define CHECK(Expr, Severity, ...) \
135149 } \
136150 } while (false)
137151
138 #define CHECK_ERR(Expr, ...) CHECK(Expr, Diligent::DebugMessageSeverity::Error, ##__VA_ARGS__)
139 #define CHECK_WARN(Expr, ...) CHECK(Expr, Diligent::DebugMessageSeverity::Warning, ##__VA_ARGS__)
140 #define CHECK_INFO(Expr, ...) CHECK(Expr, Diligent::DebugMessageSeverity::Info, ##__VA_ARGS__)
152 #define CHECK_FATAL_ERR(Expr, ...) CHECK(Expr, Diligent::DebugMessageSeverity::FatalError, ##__VA_ARGS__)
153 #define CHECK_ERR(Expr, ...) CHECK(Expr, Diligent::DebugMessageSeverity::Error, ##__VA_ARGS__)
154 #define CHECK_WARN(Expr, ...) CHECK(Expr, Diligent::DebugMessageSeverity::Warning, ##__VA_ARGS__)
155 #define CHECK_INFO(Expr, ...) CHECK(Expr, Diligent::DebugMessageSeverity::Info, ##__VA_ARGS__)
141156
142157 #define CHECK_THROW(Expr, ...) \
143158 do \