From 3c91cb09e39417f065a485ab49382d7cf9f1d4ca Mon Sep 17 00:00:00 2001 From: SparkyTD <45818400+SparkyTD@users.noreply.github.com> Date: Fri, 10 May 2024 15:52:43 -0700 Subject: [PATCH] fix: Crash caused by missing ImGui::BeginDisabled() (#1667) ### Problem description Merging my previous PRs, #1660 and #1658 has resulted in a conflict causing an application crash due to a missing `ImGui::BeginDisabled();` in the `PopupSelect` class. Specifically, none of the code related to offset validation made it into the final merge. This PR fixes the crash by reintroducing the deleted lines. ### Additional things The nightly release build seems to be unaffected by the crash, most likely because ImGui's `DisabledStack` assertions are only enforced in Debug mode. The offset validation was still missing before this fix. --- .../source/content/views/view_hex_editor.cpp | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/plugins/builtin/source/content/views/view_hex_editor.cpp b/plugins/builtin/source/content/views/view_hex_editor.cpp index 00105e497..6d378ed55 100644 --- a/plugins/builtin/source/content/views/view_hex_editor.cpp +++ b/plugins/builtin/source/content/views/view_hex_editor.cpp @@ -185,12 +185,19 @@ namespace hex::plugin::builtin { ImGui::EndTabItem(); } - if (ImGui::Button("hex.builtin.view.hex_editor.select.select"_lang) || (ImGui::IsWindowFocused() && (ImGui::IsKeyPressed(ImGuiKey_Enter) || ImGui::IsKeyPressed(ImGuiKey_KeypadEnter)))) { - editor->setSelection(m_region.getStartAddress(), m_region.getEndAddress()); - editor->jumpToSelection(); + const auto provider = ImHexApi::Provider::get(); + bool isOffsetValid = m_region.getStartAddress() <= m_region.getEndAddress() && + m_region.getEndAddress() < provider->getActualSize(); + ImGui::BeginDisabled(!isOffsetValid); + { + if (ImGui::Button("hex.builtin.view.hex_editor.select.select"_lang) || + (ImGui::IsWindowFocused() && (ImGui::IsKeyPressed(ImGuiKey_Enter) || ImGui::IsKeyPressed(ImGuiKey_KeypadEnter)))) { + editor->setSelection(m_region.getStartAddress(), m_region.getEndAddress()); + editor->jumpToSelection(); - if (!this->isPinned()) - editor->closePopup(); + if (!this->isPinned()) + editor->closePopup(); + } } ImGui::EndDisabled();