Skip to content

Commit 43546a6

Browse files
Engine and archiver factories: added SetBreakOnError method
1 parent 86fc455 commit 43546a6

File tree

12 files changed

+114
-71
lines changed

12 files changed

+114
-71
lines changed

Graphics/Archiver/interface/ArchiverFactory.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,12 @@ DILIGENT_BEGIN_INTERFACE(IArchiverFactory, IObject)
331331
/// \param [in] MessageCallback - Debug message callback function to use instead of the default one.
332332
VIRTUAL void METHOD(SetMessageCallback)(THIS_
333333
DebugMessageCallbackType MessageCallback) CONST PURE;
334+
335+
/// Sets whether to break program execution on assertion failure.
336+
337+
/// \param [in] BreakOnError - Whether to break on assertion failure.
338+
VIRTUAL void METHOD(SetBreakOnError)(THIS_
339+
bool BreakOnError) CONST PURE;
334340
};
335341
DILIGENT_END_INTERFACE
336342

@@ -346,6 +352,7 @@ DILIGENT_END_INTERFACE
346352
# define IArchiverFactory_MergeArchives(This, ...) CALL_IFACE_METHOD(ArchiverFactory, MergeArchives, This, __VA_ARGS__)
347353
# define IArchiverFactory_PrintArchiveContent(This, ...) CALL_IFACE_METHOD(ArchiverFactory, PrintArchiveContent, This, __VA_ARGS__)
348354
# define IArchiverFactory_SetMessageCallback(This, ...) CALL_IFACE_METHOD(ArchiverFactory, SetMessageCallback, This, __VA_ARGS__)
355+
# define IEngineFactory_SetBreakOnError(This, ...) CALL_IFACE_METHOD(EngineFactory, SetBreakOnError, This, __VA_ARGS__)
349356

350357
#endif
351358

Graphics/Archiver/src/ArchiverFactory.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include "ArchiverImpl.hpp"
3333
#include "SerializationDeviceImpl.hpp"
3434
#include "EngineMemory.h"
35+
#include "PlatformDebug.hpp"
3536

3637
namespace Diligent
3738
{
@@ -140,6 +141,8 @@ class ArchiverFactoryImpl final : public IArchiverFactory
140141

141142
virtual void DILIGENT_CALL_TYPE SetMessageCallback(DebugMessageCallbackType MessageCallback) const override final;
142143

144+
virtual void DILIGENT_CALL_TYPE SetBreakOnError(bool BreakOnError) const override final;
145+
143146
private:
144147
DummyReferenceCounters<ArchiverFactoryImpl> m_RefCounters;
145148
};
@@ -341,6 +344,11 @@ void ArchiverFactoryImpl::SetMessageCallback(DebugMessageCallbackType MessageCal
341344
SetDebugMessageCallback(MessageCallback);
342345
}
343346

347+
void ArchiverFactoryImpl::SetBreakOnError(bool BreakOnError) const
348+
{
349+
PlatformDebug::SetBreakOnError(BreakOnError);
350+
}
351+
344352
} // namespace
345353

346354

Graphics/GraphicsEngine/include/EngineFactoryBase.hpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019-2022 Diligent Graphics LLC
2+
* Copyright 2019-2024 Diligent Graphics LLC
33
* Copyright 2015-2019 Egor Yusov
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -38,6 +38,7 @@
3838
#include "DummyReferenceCounters.hpp"
3939
#include "EngineMemory.h"
4040
#include "RefCntAutoPtr.hpp"
41+
#include "PlatformDebug.hpp"
4142

4243
namespace Diligent
4344
{
@@ -116,6 +117,11 @@ class EngineFactoryBase : public BaseInterface
116117
SetDebugMessageCallback(MessageCallback);
117118
}
118119

120+
virtual void DILIGENT_CALL_TYPE SetBreakOnError(bool BreakOnError) const override final
121+
{
122+
PlatformDebug::SetBreakOnError(BreakOnError);
123+
}
124+
119125
protected:
120126
template <typename DearchiverImplType>
121127
void CreateDearchiver(const DearchiverCreateInfo& CreateInfo,

Graphics/GraphicsEngine/interface/EngineFactory.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019-2023 Diligent Graphics LLC
2+
* Copyright 2019-2024 Diligent Graphics LLC
33
* Copyright 2015-2019 Egor Yusov
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -132,6 +132,12 @@ DILIGENT_BEGIN_INTERFACE(IEngineFactory, IObject)
132132
VIRTUAL void METHOD(SetMessageCallback)(THIS_
133133
DebugMessageCallbackType MessageCallback) CONST PURE;
134134

135+
/// Sets whether to break program execution on assertion failure.
136+
137+
/// \param [in] BreakOnError - Whether to break on assertion failure.
138+
VIRTUAL void METHOD(SetBreakOnError)(THIS_
139+
bool BreakOnError) CONST PURE;
140+
135141
#if PLATFORM_ANDROID
136142
/// On Android platform, it is necessary to initialize the file system before
137143
/// CreateDefaultShaderSourceStreamFactory() method can be called.
@@ -164,7 +170,7 @@ DILIGENT_END_INTERFACE
164170
# define IEngineFactory_InitAndroidFileSystem(This, ...) CALL_IFACE_METHOD(EngineFactory, InitAndroidFileSystem, This, __VA_ARGS__)
165171
# define IEngineFactory_CreateDearchiver(This, ...) CALL_IFACE_METHOD(EngineFactory, CreateDearchiver, This, __VA_ARGS__)
166172
# define IEngineFactory_SetMessageCallback(This, ...) CALL_IFACE_METHOD(EngineFactory, SetMessageCallback, This, __VA_ARGS__)
167-
173+
# define IEngineFactory_SetBreakOnError(This, ...) CALL_IFACE_METHOD(EngineFactory, SetBreakOnError, This, __VA_ARGS__)
168174
// clang-format on
169175

170176
#endif

Platforms/Android/src/AndroidDebug.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,11 @@ void AndroidDebug::AssertionFailed(const Char* Message, const char* Function, co
4444
else
4545
{
4646
OutputDebugMessage(DEBUG_MESSAGE_SEVERITY_ERROR, AssertionFailedMessage.c_str(), nullptr, nullptr, 0);
47-
if (GetBreakOnError())
48-
{
49-
raise(SIGTRAP);
50-
}
47+
}
48+
49+
if (GetBreakOnError())
50+
{
51+
raise(SIGTRAP);
5152
}
5253
}
5354

Platforms/Apple/src/AppleDebug.mm

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,11 @@
4444
else
4545
{
4646
OutputDebugMessage(DEBUG_MESSAGE_SEVERITY_ERROR, AssertionFailedMessage.c_str(), nullptr, nullptr, 0);
47-
if (GetBreakOnError())
48-
{
49-
raise(SIGTRAP);
50-
}
47+
}
48+
49+
if (GetBreakOnError())
50+
{
51+
raise(SIGTRAP);
5152
}
5253
}
5354

Platforms/Emscripten/src/EmscriptenDebug.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,11 @@ void EmscriptenDebug::AssertionFailed(const Char* Message, const char* Function,
4343
else
4444
{
4545
OutputDebugMessage(DEBUG_MESSAGE_SEVERITY_ERROR, AssertionFailedMessage.c_str(), nullptr, nullptr, 0);
46-
if (GetBreakOnError())
47-
{
48-
raise(SIGTRAP);
49-
}
46+
}
47+
48+
if (GetBreakOnError())
49+
{
50+
raise(SIGTRAP);
5051
}
5152
}
5253

Platforms/Linux/src/LinuxDebug.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,11 @@ void LinuxDebug::AssertionFailed(const Char* Message, const char* Function, cons
4444
else
4545
{
4646
OutputDebugMessage(DEBUG_MESSAGE_SEVERITY_ERROR, AssertionFailedMessage.c_str(), nullptr, nullptr, 0);
47-
if (GetBreakOnError())
48-
{
49-
raise(SIGTRAP);
50-
}
47+
}
48+
49+
if (GetBreakOnError())
50+
{
51+
raise(SIGTRAP);
5152
}
5253
}
5354

Platforms/UWP/src/UWPDebug.cpp

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -46,37 +46,38 @@ void WindowsStoreDebug::AssertionFailed(const Char* Message, const char* Functio
4646
else
4747
{
4848
OutputDebugMessage(DEBUG_MESSAGE_SEVERITY_ERROR, AssertionFailedMessage.c_str(), nullptr, nullptr, 0);
49-
if (GetBreakOnError())
50-
{
51-
__debugbreak();
52-
//int nCode = MessageBoxA(NULL,
53-
// FullMsg.c_str(),
54-
// "Runtime assertion failed",
55-
// MB_TASKMODAL|MB_ICONHAND|MB_ABORTRETRYIGNORE|MB_SETFOREGROUND);
49+
}
50+
51+
if (GetBreakOnError())
52+
{
53+
__debugbreak();
54+
//int nCode = MessageBoxA(NULL,
55+
// FullMsg.c_str(),
56+
// "Runtime assertion failed",
57+
// MB_TASKMODAL|MB_ICONHAND|MB_ABORTRETRYIGNORE|MB_SETFOREGROUND);
5658

57-
//// Abort: abort the program
58-
//if (nCode == IDABORT)
59-
//{
60-
// // raise abort signal
61-
// raise(SIGABRT);
59+
//// Abort: abort the program
60+
//if (nCode == IDABORT)
61+
//{
62+
// // raise abort signal
63+
// raise(SIGABRT);
6264

63-
// // We usually won't get here, but it's possible that
64-
// // SIGABRT was ignored. So exit the program anyway.
65-
// exit(3);
66-
//}
65+
// // We usually won't get here, but it's possible that
66+
// // SIGABRT was ignored. So exit the program anyway.
67+
// exit(3);
68+
//}
6769

68-
//// Retry: call the debugger
69-
//if (nCode == IDRETRY)
70-
//{
71-
// DebugBreak();
72-
// /* return to user code */
73-
// return;
74-
//}
70+
//// Retry: call the debugger
71+
//if (nCode == IDRETRY)
72+
//{
73+
// DebugBreak();
74+
// /* return to user code */
75+
// return;
76+
//}
7577

76-
//// Ignore: continue execution
77-
//if (nCode == IDIGNORE)
78-
// return;
79-
}
78+
//// Ignore: continue execution
79+
//if (nCode == IDIGNORE)
80+
// return;
8081
}
8182
}
8283

Platforms/Win32/src/Win32Debug.cpp

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -79,36 +79,37 @@ void WindowsDebug::AssertionFailed(const Char* Message, const char* Function, co
7979
else
8080
{
8181
OutputDebugMessage(DEBUG_MESSAGE_SEVERITY_ERROR, AssertionFailedMessage.c_str(), nullptr, nullptr, 0);
82-
if (GetBreakOnError())
83-
{
84-
int nCode = MessageBoxA(NULL,
85-
AssertionFailedMessage.c_str(),
86-
"Runtime assertion failed",
87-
MB_TASKMODAL | MB_ICONHAND | MB_ABORTRETRYIGNORE | MB_SETFOREGROUND);
82+
}
8883

89-
// Abort: abort the program
90-
if (nCode == IDABORT)
91-
{
92-
// raise abort signal
93-
raise(SIGABRT);
84+
if (GetBreakOnError())
85+
{
86+
int nCode = MessageBoxA(NULL,
87+
AssertionFailedMessage.c_str(),
88+
"Runtime assertion failed",
89+
MB_TASKMODAL | MB_ICONHAND | MB_ABORTRETRYIGNORE | MB_SETFOREGROUND);
9490

95-
// We usually won't get here, but it's possible that
96-
// SIGABRT was ignored. So exit the program anyway.
97-
exit(3);
98-
}
91+
// Abort: abort the program
92+
if (nCode == IDABORT)
93+
{
94+
// raise abort signal
95+
raise(SIGABRT);
9996

100-
// Retry: call the debugger
101-
if (nCode == IDRETRY)
102-
{
103-
DebugBreak();
104-
// return to user code
105-
return;
106-
}
97+
// We usually won't get here, but it's possible that
98+
// SIGABRT was ignored. So exit the program anyway.
99+
exit(3);
100+
}
107101

108-
// Ignore: continue execution
109-
if (nCode == IDIGNORE)
110-
return;
102+
// Retry: call the debugger
103+
if (nCode == IDRETRY)
104+
{
105+
DebugBreak();
106+
// return to user code
107+
return;
111108
}
109+
110+
// Ignore: continue execution
111+
if (nCode == IDIGNORE)
112+
return;
112113
}
113114
}
114115

0 commit comments

Comments
 (0)