From aa7c5422c0579f280d7e6907b0da6ce4158e49ab Mon Sep 17 00:00:00 2001 From: WerWolv Date: Tue, 11 Apr 2023 15:26:18 +0200 Subject: [PATCH] fix: Make sure provider data is properly cleared when deleting provider --- lib/libimhex/source/api/imhex_api.cpp | 3 +-- .../include/content/helpers/provider_extra_data.hpp | 9 ++++++++- plugins/builtin/source/content/events.cpp | 1 + plugins/builtin/source/content/views/view_hex_editor.cpp | 3 +++ 4 files changed, 13 insertions(+), 3 deletions(-) diff --git a/lib/libimhex/source/api/imhex_api.cpp b/lib/libimhex/source/api/imhex_api.cpp index 54d4d76fa..602614935 100644 --- a/lib/libimhex/source/api/imhex_api.cpp +++ b/lib/libimhex/source/api/imhex_api.cpp @@ -297,8 +297,6 @@ namespace hex { if (it == s_providers.end()) return; - EventManager::post(provider); - if (!s_providers.empty() && it - s_providers.begin() == s_currentProvider) setCurrentProvider(0); @@ -310,6 +308,7 @@ namespace hex { EventManager::post(provider); TaskManager::runWhenTasksFinished([provider] { + EventManager::post(provider); delete provider; }); } diff --git a/plugins/builtin/include/content/helpers/provider_extra_data.hpp b/plugins/builtin/include/content/helpers/provider_extra_data.hpp index b7a746136..c745f47f0 100644 --- a/plugins/builtin/include/content/helpers/provider_extra_data.hpp +++ b/plugins/builtin/include/content/helpers/provider_extra_data.hpp @@ -8,6 +8,8 @@ #include #include +#include + #include #include @@ -18,6 +20,10 @@ namespace hex::plugin::builtin { class ProviderExtraData { public: struct Data { + Data() : patternLanguage(), bookmarks(), dataProcessor(), editor(), hashes(), yara() { + log::debug("Creating new extra data instance"); + } + bool dataDirty = false; struct PatternLanguage { @@ -88,7 +94,7 @@ namespace hex::plugin::builtin { } dataProcessor; struct HexEditor { - std::optional selectionStart, selectionEnd; + std::optional selectionStart = std::nullopt, selectionEnd = std::nullopt; float scrollPosition = 0.0F; } editor; @@ -132,6 +138,7 @@ namespace hex::plugin::builtin { private: ProviderExtraData() = default; + static inline std::map s_data = {}; }; diff --git a/plugins/builtin/source/content/events.cpp b/plugins/builtin/source/content/events.cpp index 2caf52d85..bb4630dda 100644 --- a/plugins/builtin/source/content/events.cpp +++ b/plugins/builtin/source/content/events.cpp @@ -78,6 +78,7 @@ namespace hex::plugin::builtin { EventManager::subscribe([](hex::prv::Provider *provider) { if (provider != nullptr && ImHexApi::Provider::get() == provider) EventManager::post(); + EventManager::post(nullptr, provider); }); EventManager::subscribe(openFile); diff --git a/plugins/builtin/source/content/views/view_hex_editor.cpp b/plugins/builtin/source/content/views/view_hex_editor.cpp index f3e87986a..d354732fb 100644 --- a/plugins/builtin/source/content/views/view_hex_editor.cpp +++ b/plugins/builtin/source/content/views/view_hex_editor.cpp @@ -942,6 +942,9 @@ namespace hex::plugin::builtin { } } + this->m_hexEditor.setSelectionUnchecked(std::nullopt, std::nullopt); + this->m_hexEditor.setScrollPosition(0); + if (newProvider != nullptr) { auto &newData = ProviderExtraData::get(newProvider).editor;