Skip to content

Commit

Permalink
Merge pull request #538 from WSSDude420/imgui-custom-assertion
Browse files Browse the repository at this point in the history
Override ImGui asserts by custom definition for more granular control
  • Loading branch information
Yamashi authored Apr 2, 2021
2 parents 9312eab + dac8e1e commit 5735670
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
19 changes: 19 additions & 0 deletions src/imgui_impl/imgui_user_config.cpp
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);
}
12 changes: 12 additions & 0 deletions src/imgui_impl/imgui_user_config.h
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))))
6 changes: 4 additions & 2 deletions xmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ set_arch("x64")
add_requires("spdlog", "nlohmann_json", "hopscotch-map", "minhook", "mem", "imgui 1.82", "sol2", "tiltedcore 0.2.2", "sqlite3", "luajit")
add_requireconfs("sol2", { configs = { includes_lua = false } })

local imguiUserConfig = path.absolute("src/imgui_impl/imgui_user_config.h")
add_requireconfs("imgui", { configs = { user_config = imguiUserConfig } })

add_rules("mode.debug","mode.releasedbg", "mode.release")
add_rules("plugin.vsxmake.autoupdate")

Expand All @@ -16,7 +19,6 @@ elseif is_mode("releasedbg") then
add_defines("CET_DEBUG")
set_optimize("fastest")
elseif is_mode("release") then
add_requireconfs("imgui", { configs = { cxflags = "/DNDEBUG" } })
add_defines("NDEBUG")
set_optimize("fastest")
end
Expand Down Expand Up @@ -59,7 +61,7 @@ target("RED4ext.SDK")
add_includedirs("vendor/RED4ext.SDK/include/", { public = true })

target("cyber_engine_tweaks")
add_defines("WIN32_LEAN_AND_MEAN", "NOMINMAX", "SOL_ALL_SAFETIES_ON", "WINVER=0x0601", "SOL_LUAJIT=1") -- WINVER=0x0601 == Windows 7, we need this specified now for some reason
add_defines("WIN32_LEAN_AND_MEAN", "NOMINMAX", "WINVER=0x0601", "SOL_ALL_SAFETIES_ON", "SOL_LUAJIT=1", "SPDLOG_WCHAR_TO_UTF8_SUPPORT", "IMGUI_USER_CONFIG=\""..imguiUserConfig.."\"") -- WINVER=0x0601 == Windows 7, we need this specified now for some reason
set_pcxxheader("src/stdafx.h")
set_kind("shared")
set_filename("cyber_engine_tweaks.asi")
Expand Down

0 comments on commit 5735670

Please sign in to comment.