fix: Crash when closing provider that had pattern loaded in some cases
This commit is contained in:
parent
90d9c91717
commit
27790532f8
@ -19,7 +19,6 @@ namespace hex::plugin::builtin {
|
||||
void drawContent() override;
|
||||
|
||||
private:
|
||||
std::map<hex::prv::Provider *, std::vector<pl::ptrn::Pattern*>> m_sortedPatterns;
|
||||
ui::PatternDrawer m_patternDrawer;
|
||||
};
|
||||
|
||||
|
@ -19,6 +19,7 @@ namespace hex::plugin::builtin::ui {
|
||||
};
|
||||
|
||||
void setTreeStyle(TreeStyle style) { this->m_treeStyle = style; }
|
||||
void reset();
|
||||
|
||||
private:
|
||||
void draw(pl::ptrn::Pattern& pattern);
|
||||
@ -64,5 +65,7 @@ namespace hex::plugin::builtin::ui {
|
||||
const pl::ptrn::Pattern *m_editingPattern = nullptr;
|
||||
TreeStyle m_treeStyle = TreeStyle::Default;
|
||||
pl::ptrn::Pattern *m_currVisualizedPattern = nullptr;
|
||||
|
||||
std::set<pl::ptrn::Pattern*> m_visualizedPatterns;
|
||||
};
|
||||
}
|
@ -11,26 +11,21 @@ namespace hex::plugin::builtin {
|
||||
|
||||
ViewPatternData::ViewPatternData() : View("hex.builtin.view.pattern_data.name") {
|
||||
|
||||
EventManager::subscribe<EventHighlightingChanged>(this, [this]() {
|
||||
if (!ImHexApi::Provider::isValid()) return;
|
||||
|
||||
this->m_sortedPatterns[ImHexApi::Provider::get()].clear();
|
||||
});
|
||||
|
||||
EventManager::subscribe<EventProviderClosed>([this](auto *provider) {
|
||||
this->m_sortedPatterns[provider].clear();
|
||||
});
|
||||
|
||||
EventManager::subscribe<EventSettingsChanged>([this]() {
|
||||
EventManager::subscribe<EventSettingsChanged>(this, [this]() {
|
||||
auto patternStyle = ContentRegistry::Settings::getSetting("hex.builtin.setting.interface", "hex.builtin.setting.interface.pattern_tree_style");
|
||||
|
||||
if (patternStyle.is_number())
|
||||
this->m_patternDrawer.setTreeStyle(static_cast<ui::PatternDrawer::TreeStyle>(patternStyle.get<int>()));
|
||||
});
|
||||
|
||||
EventManager::subscribe<EventProviderChanged>(this, [this](auto, auto) {
|
||||
this->m_patternDrawer.reset();
|
||||
});
|
||||
}
|
||||
|
||||
ViewPatternData::~ViewPatternData() {
|
||||
EventManager::unsubscribe<EventHighlightingChanged>(this);
|
||||
EventManager::unsubscribe<EventSettingsChanged>(this);
|
||||
EventManager::unsubscribe<EventProviderChanged>(this);
|
||||
}
|
||||
|
||||
void ViewPatternData::drawContent() {
|
||||
@ -48,6 +43,9 @@ namespace hex::plugin::builtin {
|
||||
}
|
||||
}();
|
||||
|
||||
if (!patternLanguage.executionDone)
|
||||
this->m_patternDrawer.reset();
|
||||
|
||||
this->m_patternDrawer.draw(patterns);
|
||||
}
|
||||
}
|
||||
|
@ -96,7 +96,7 @@ namespace hex::plugin::builtin {
|
||||
ViewPatternEditor::~ViewPatternEditor() {
|
||||
EventManager::unsubscribe<RequestSetPatternLanguageCode>(this);
|
||||
EventManager::unsubscribe<EventFileLoaded>(this);
|
||||
EventManager::unsubscribe<EventProviderDeleted>(this);
|
||||
EventManager::unsubscribe<EventProviderOpened>(this);
|
||||
EventManager::unsubscribe<RequestChangeTheme>(this);
|
||||
EventManager::unsubscribe<EventProviderChanged>(this);
|
||||
}
|
||||
|
@ -140,19 +140,17 @@ namespace hex::plugin::builtin::ui {
|
||||
|
||||
void PatternDrawer::drawVisualizerButton(pl::ptrn::Pattern& pattern, pl::ptrn::Iteratable &iteratable) {
|
||||
if (const auto &arguments = pattern.getAttributeArguments("hex::visualize"); !arguments.empty()) {
|
||||
static bool shouldReset = false;
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(0, 0));
|
||||
if (ImGui::Button(pattern.getFormattedValue().c_str(), ImVec2(-1, ImGui::GetTextLineHeight()))) {
|
||||
this->m_currVisualizedPattern = &pattern;
|
||||
shouldReset = true;
|
||||
ImGui::OpenPopup("Visualizer");
|
||||
}
|
||||
ImGui::PopStyleVar();
|
||||
|
||||
if (ImGui::BeginPopup("Visualizer")) {
|
||||
if (this->m_currVisualizedPattern == &pattern) {
|
||||
drawVisualizer(arguments, pattern, iteratable, shouldReset);
|
||||
shouldReset = false;
|
||||
drawVisualizer(arguments, pattern, iteratable, !this->m_visualizedPatterns.contains(&pattern));
|
||||
this->m_visualizedPatterns.insert(&pattern);
|
||||
}
|
||||
|
||||
ImGui::EndPopup();
|
||||
@ -835,4 +833,12 @@ namespace hex::plugin::builtin::ui {
|
||||
ImGui::EndTable();
|
||||
}
|
||||
}
|
||||
|
||||
void PatternDrawer::reset() {
|
||||
this->m_editingPattern = nullptr;
|
||||
this->m_displayEnd.clear();
|
||||
this->m_visualizedPatterns.clear();
|
||||
this->m_currVisualizedPattern = nullptr;
|
||||
this->m_sortedPatterns.clear();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user