1
0
mirror of synced 2025-01-31 03:53:44 +01:00

fix: Make sure provider data is properly cleared when deleting provider

This commit is contained in:
WerWolv 2023-04-11 15:26:18 +02:00
parent 5512585cc5
commit aa7c5422c0
4 changed files with 13 additions and 3 deletions

View File

@ -297,8 +297,6 @@ namespace hex {
if (it == s_providers.end())
return;
EventManager::post<EventProviderDeleted>(provider);
if (!s_providers.empty() && it - s_providers.begin() == s_currentProvider)
setCurrentProvider(0);
@ -310,6 +308,7 @@ namespace hex {
EventManager::post<EventProviderClosed>(provider);
TaskManager::runWhenTasksFinished([provider] {
EventManager::post<EventProviderDeleted>(provider);
delete provider;
});
}

View File

@ -8,6 +8,8 @@
#include <hex/data_processor/node.hpp>
#include <hex/data_processor/link.hpp>
#include <hex/helpers/logger.hpp>
#include <map>
#include <imnodes.h>
@ -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<u64> selectionStart, selectionEnd;
std::optional<u64> 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<const hex::prv::Provider*, Data> s_data = {};
};

View File

@ -78,6 +78,7 @@ namespace hex::plugin::builtin {
EventManager::subscribe<EventProviderOpened>([](hex::prv::Provider *provider) {
if (provider != nullptr && ImHexApi::Provider::get() == provider)
EventManager::post<RequestUpdateWindowTitle>();
EventManager::post<EventProviderChanged>(nullptr, provider);
});
EventManager::subscribe<RequestOpenFile>(openFile);

View File

@ -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;