Skip to content

Commit 49bba13

Browse files
committed
xrCore/xrDebug.cpp: setup an assertion handler for SDL2
1 parent cf7eea6 commit 49bba13

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/xrCore/xrDebug.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ ICN void* GetInstructionPtr()
9595
}
9696
}
9797

98+
// XXX: Probably rename this to AssertionResult?
9899
enum MessageBoxResult
99100
{
100101
resultUndefined = -1,
@@ -171,6 +172,23 @@ int xrDebug::ShowMessage(pcstr title, pcstr message, bool simple)
171172
#endif
172173
}
173174

175+
SDL_AssertState SDLAssertionHandler(const SDL_AssertData* data,
176+
void* userdata)
177+
{
178+
if (data->always_ignore)
179+
return SDL_ASSERTION_ALWAYS_IGNORE;
180+
181+
constexpr pcstr desc = "SDL2 assert triggered";
182+
bool alwaysIgnore = false;
183+
xrDebug::Fail(alwaysIgnore, {data->filename, data->linenum, data->function}, data->condition, desc);
184+
185+
if (alwaysIgnore)
186+
return SDL_ASSERTION_ALWAYS_IGNORE;
187+
188+
// XXX: change Fail return type from void to 'enum MessageBoxResult'
189+
return SDL_ASSERTION_IGNORE;
190+
}
191+
174192
SDL_Window* xrDebug::applicationWindow = nullptr;
175193
xrDebug::UnhandledExceptionFilter xrDebug::PrevFilter = nullptr;
176194
xrDebug::OutOfMemoryCallbackFunc xrDebug::OutOfMemoryCallback = nullptr;
@@ -837,6 +855,7 @@ void xrDebug::Initialize(const bool& dedicated)
837855
*BugReportFile = 0;
838856
OnThreadSpawn();
839857
SetupExceptionHandler(dedicated);
858+
SDL_SetAssertionHandler(SDLAssertionHandler, nullptr);
840859
// exception handler to all "unhandled" exceptions
841860
#if defined(WINDOWS)
842861
PrevFilter = ::SetUnhandledExceptionFilter(UnhandledFilter);

0 commit comments

Comments
 (0)