feat: Added option to enable debug features in release builds

This commit is contained in:
WerWolv
2025-01-25 15:38:57 +01:00
parent f4bad0053a
commit a44959ce1b
5 changed files with 114 additions and 82 deletions

View File

@@ -23,7 +23,7 @@
namespace hex::plugin::builtin {
void addTitleBarButtons() {
#if defined(DEBUG)
if (dbg::debugModeEnabled()) {
ContentRegistry::Interface::addTitleBarButton(ICON_VS_DEBUG, "hex.builtin.title_bar_button.debug_build", []{
if (ImGui::GetIO().KeyShift) {
RequestOpenPopup::post("DebugMenu");
@@ -31,7 +31,7 @@ namespace hex::plugin::builtin {
hex::openWebpage("https://imhex.werwolv.net/debug");
}
});
#endif
}
ContentRegistry::Interface::addTitleBarButton(ICON_VS_SMILEY, "hex.builtin.title_bar_button.feedback", []{
hex::openWebpage("https://github.com/WerWolv/ImHex/discussions/categories/feedback");
@@ -50,89 +50,85 @@ namespace hex::plugin::builtin {
}
}
#if defined(DEBUG)
static void drawDebugPopup() {
static bool showImGuiDemo = false;
static bool showImPlotDemo = false;
static bool showImPlot3DDemo = false;
static void drawDebugPopup() {
static bool showImGuiDemo = false;
static bool showImPlotDemo = false;
static bool showImPlot3DDemo = false;
ImGui::SetNextWindowSize(scaled({ 300, 150 }), ImGuiCond_Always);
if (ImGui::BeginPopup("DebugMenu")) {
if (ImGui::BeginTabBar("DebugTabBar")) {
if (ImGui::BeginTabItem("ImHex")) {
if (ImGui::BeginChild("Scrolling", ImGui::GetContentRegionAvail())) {
ImGui::Checkbox("Show Debug Variables", &dbg::impl::getDebugWindowState());
ImGui::SetNextWindowSize(scaled({ 300, 150 }), ImGuiCond_Always);
if (ImGui::BeginPopup("DebugMenu")) {
if (ImGui::BeginTabBar("DebugTabBar")) {
if (ImGui::BeginTabItem("ImHex")) {
if (ImGui::BeginChild("Scrolling", ImGui::GetContentRegionAvail())) {
ImGui::Checkbox("Show Debug Variables", &dbg::impl::getDebugWindowState());
ImGuiExt::Header("Information");
ImGuiExt::TextFormatted("Running Tasks: {0}", TaskManager::getRunningTaskCount());
ImGuiExt::TextFormatted("Running Background Tasks: {0}", TaskManager::getRunningBackgroundTaskCount());
ImGuiExt::TextFormatted("Last Frame Time: {0:.3f}ms", ImHexApi::System::getLastFrameTime() * 1000.0F);
}
ImGui::EndChild();
ImGui::EndTabItem();
ImGuiExt::Header("Information");
ImGuiExt::TextFormatted("Running Tasks: {0}", TaskManager::getRunningTaskCount());
ImGuiExt::TextFormatted("Running Background Tasks: {0}", TaskManager::getRunningBackgroundTaskCount());
ImGuiExt::TextFormatted("Last Frame Time: {0:.3f}ms", ImHexApi::System::getLastFrameTime() * 1000.0F);
}
if (ImGui::BeginTabItem("ImGui")) {
if (ImGui::BeginChild("Scrolling", ImGui::GetContentRegionAvail())) {
auto ctx = ImGui::GetCurrentContext();
ImGui::Checkbox("Show ImGui Demo", &showImGuiDemo);
ImGui::Checkbox("Show ImPlot Demo", &showImPlotDemo);
ImGui::Checkbox("Show ImPlot3D Demo", &showImPlot3DDemo);
ImGui::EndChild();
if (ImGui::Button("Trigger Breakpoint in Item") || ctx->DebugItemPickerActive)
ImGui::DebugStartItemPicker();
}
ImGui::EndChild();
ImGui::EndTabItem();
}
if (ImGui::BeginTabItem("Crashes")) {
if (ImGui::BeginChild("Scrolling", ImGui::GetContentRegionAvail())) {
if (ImGui::Button("Throw Exception")) {
TaskManager::doLater([] {
throw std::runtime_error("Test exception");
});
}
if (ImGui::Button("Access Invalid Memory")) {
TaskManager::doLater([] {
*reinterpret_cast<u32*>(0x10) = 0x10;
std::unreachable();
});
}
if (ImGui::Button("Raise SIGSEGV")) {
TaskManager::doLater([] {
raise(SIGSEGV);
});
}
if (ImGui::Button("Corrupt Memory")) {
TaskManager::doLater([] {
auto bytes = new u8[0xFFFFF];
delete[] bytes;
delete[] bytes;
});
}
}
ImGui::EndChild();
ImGui::EndTabItem();
}
ImGui::EndTabBar();
ImGui::EndTabItem();
}
ImGui::EndPopup();
}
if (ImGui::BeginTabItem("ImGui")) {
if (ImGui::BeginChild("Scrolling", ImGui::GetContentRegionAvail())) {
auto ctx = ImGui::GetCurrentContext();
ImGui::Checkbox("Show ImGui Demo", &showImGuiDemo);
ImGui::Checkbox("Show ImPlot Demo", &showImPlotDemo);
ImGui::Checkbox("Show ImPlot3D Demo", &showImPlot3DDemo);
if (showImGuiDemo)
ImGui::ShowDemoWindow(&showImGuiDemo);
if (showImPlotDemo)
ImPlot::ShowDemoWindow(&showImPlotDemo);
if (showImPlot3DDemo)
ImPlot3D::ShowDemoWindow(&showImPlot3DDemo);
if (ImGui::Button("Trigger Breakpoint in Item") || ctx->DebugItemPickerActive)
ImGui::DebugStartItemPicker();
}
ImGui::EndChild();
ImGui::EndTabItem();
}
if (ImGui::BeginTabItem("Crashes")) {
if (ImGui::BeginChild("Scrolling", ImGui::GetContentRegionAvail())) {
if (ImGui::Button("Throw Exception")) {
TaskManager::doLater([] {
throw std::runtime_error("Test exception");
});
}
if (ImGui::Button("Access Invalid Memory")) {
TaskManager::doLater([] {
*reinterpret_cast<u32*>(0x10) = 0x10;
std::unreachable();
});
}
if (ImGui::Button("Raise SIGSEGV")) {
TaskManager::doLater([] {
raise(SIGSEGV);
});
}
if (ImGui::Button("Corrupt Memory")) {
TaskManager::doLater([] {
auto bytes = new u8[0xFFFFF];
delete[] bytes;
delete[] bytes;
});
}
}
ImGui::EndChild();
ImGui::EndTabItem();
}
ImGui::EndTabBar();
}
ImGui::EndPopup();
}
#endif
if (showImGuiDemo)
ImGui::ShowDemoWindow(&showImGuiDemo);
if (showImPlotDemo)
ImPlot::ShowDemoWindow(&showImPlotDemo);
if (showImPlot3DDemo)
ImPlot3D::ShowDemoWindow(&showImPlot3DDemo);
}
static bool s_drawDragDropOverlay = false;
static void drawDragNDropOverlay() {
@@ -178,9 +174,9 @@ namespace hex::plugin::builtin {
EventFrameEnd::subscribe(drawGlobalPopups);
EventFrameEnd::subscribe(drawDragNDropOverlay);
#if defined(DEBUG)
if (dbg::debugModeEnabled()) {
EventFrameEnd::subscribe(drawDebugPopup);
#endif
}
EventFileDragged::subscribe([](bool entered) {
s_drawDragDropOverlay = entered;
@@ -196,7 +192,7 @@ namespace hex::plugin::builtin {
});
}
#if defined(DEBUG)
if (dbg::debugModeEnabled()) {
ContentRegistry::Interface::addFooterItem([] {
static float framerate = 0;
if (ImGuiExt::HasSecondPassed()) {
@@ -237,7 +233,7 @@ namespace hex::plugin::builtin {
ImGui::PopStyleVar();
}
});
#endif
}
ContentRegistry::Interface::addFooterItem([] {
static bool shouldResetProgress = false;