-
-
Notifications
You must be signed in to change notification settings - Fork 291
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #538 from WSSDude420/imgui-custom-assertion
Override ImGui asserts by custom definition for more granular control
- Loading branch information
Showing
3 changed files
with
35 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#include <stdafx.h> | ||
|
||
// NOTE: imgui_user_config.h is included by imgui.h which is included with precompiled header, so no need to include it here once more | ||
|
||
// global definition "Enable ImGui Assertions" | ||
bool g_ImGuiAssertionsEnabled{ true }; | ||
|
||
#ifdef NDEBUG | ||
// inline _wassert decl for NDEBUG as it is not emitted inside assert.h header in this case | ||
extern "C" _ACRTIMP void __cdecl _wassert(wchar_t const* _Message, wchar_t const* _File, unsigned _Line); | ||
#endif | ||
|
||
// runtime assertions which can be enabled/disabled inside CET options | ||
void ImGuiAssert(wchar_t const* acpMessage, wchar_t const* acpFile, unsigned aLine) | ||
{ | ||
// TODO - it looks like assertions dont get logged for some weird reason, even though there is flush_on set for errors (even higher for debug) | ||
spdlog::error(L"ImGui assertion failed in file \"{ 0 }\" at line { 1 }! Expression ({ 2 }) evaluates to false!", acpFile, aLine, acpMessage); | ||
_wassert(acpMessage, acpFile, aLine); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#pragma once | ||
|
||
// global declaration "Enable ImGui Assertions" | ||
extern bool g_ImGuiAssertionsEnabled; | ||
|
||
// runtime assertions which can be enabled/disabled inside CET options | ||
void ImGuiAssert(wchar_t const* acpMessage, wchar_t const* acpFile, unsigned aLine); | ||
|
||
// custom assertion function macro for ImGui | ||
#define IM_ASSERT(expression) (void)( \ | ||
(g_ImGuiAssertionsEnabled && ((!!(expression)) || \ | ||
(ImGuiAssert(_CRT_WIDE(#expression), _CRT_WIDE(__FILE__), (unsigned)(__LINE__)), 0)))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters