From 60649d1cba9bed0a39dbe4570af21ae013380a6a Mon Sep 17 00:00:00 2001 From: WerWolv Date: Wed, 30 Aug 2023 09:18:24 +0200 Subject: [PATCH] fix: Occasional crash when using favorites --- plugins/builtin/romfs/lang/de_DE.json | 1 - plugins/builtin/romfs/lang/en_US.json | 1 - plugins/builtin/romfs/lang/zh_CN.json | 1 - plugins/builtin/source/ui/pattern_drawer.cpp | 47 +++++++++++--------- 4 files changed, 25 insertions(+), 25 deletions(-) diff --git a/plugins/builtin/romfs/lang/de_DE.json b/plugins/builtin/romfs/lang/de_DE.json index 37443b9b6..982e1bbe0 100644 --- a/plugins/builtin/romfs/lang/de_DE.json +++ b/plugins/builtin/romfs/lang/de_DE.json @@ -947,7 +947,6 @@ "hex.builtin.common.deny": "Verweigern", "hex.builtin.common.warning": "Warnung", "hex.builtin.pattern_drawer.export": "Pattern exportieren als...", - "hex.builtin.pattern_drawer.updating": "Favoriten werden aktualisiert...", "hex.builtin.pl_visualizer.coordinates.latitude": "Breitengrade", "hex.builtin.pl_visualizer.coordinates.longitude": "Längengrad", "hex.builtin.pl_visualizer.coordinates.query": "Adresse finden", diff --git a/plugins/builtin/romfs/lang/en_US.json b/plugins/builtin/romfs/lang/en_US.json index 328a21fb1..41f100e7a 100644 --- a/plugins/builtin/romfs/lang/en_US.json +++ b/plugins/builtin/romfs/lang/en_US.json @@ -436,7 +436,6 @@ "hex.builtin.pattern_drawer.tree_style.auto_expanded": "Auto Expanded Tree", "hex.builtin.pattern_drawer.tree_style.flattened": "Flattened", "hex.builtin.pattern_drawer.type": "Type", - "hex.builtin.pattern_drawer.updating": "Updating Favorites...", "hex.builtin.pattern_drawer.value": "Value", "hex.builtin.pattern_drawer.var_name": "Name", "hex.builtin.pattern_drawer.visualizer.unknown": "Unknown visualizer", diff --git a/plugins/builtin/romfs/lang/zh_CN.json b/plugins/builtin/romfs/lang/zh_CN.json index 3356a7f49..8d0cdf3f1 100644 --- a/plugins/builtin/romfs/lang/zh_CN.json +++ b/plugins/builtin/romfs/lang/zh_CN.json @@ -948,7 +948,6 @@ "hex.builtin.pattern_drawer.end": "结束", "hex.builtin.pattern_drawer.export": "导出为...", "hex.builtin.pattern_drawer.start": "开始", - "hex.builtin.pattern_drawer.updating": "正在更新收藏...", "hex.builtin.pl_visualizer.coordinates.latitude": "维度", "hex.builtin.pl_visualizer.coordinates.longitude": "精度", "hex.builtin.pl_visualizer.coordinates.query": "查找地址", diff --git a/plugins/builtin/source/ui/pattern_drawer.cpp b/plugins/builtin/source/ui/pattern_drawer.cpp index 645009daf..edee73944 100644 --- a/plugins/builtin/source/ui/pattern_drawer.cpp +++ b/plugins/builtin/source/ui/pattern_drawer.cpp @@ -37,6 +37,8 @@ namespace hex::plugin::builtin::ui { namespace { + std::mutex s_favoritesMutex; + constexpr auto DisplayEndDefault = 50U; using namespace ::std::literals::string_literals; @@ -1086,6 +1088,8 @@ namespace hex::plugin::builtin::ui { if (!patterns.empty() && !this->m_favoritesUpdateTask.isRunning()) { this->m_favoritesUpdateTask = TaskManager::createTask("hex.builtin.pattern_drawer.updating"_lang, TaskManager::NoProgress, [this, patterns](auto &task) { size_t updatedFavorites = 0; + + std::scoped_lock lock(s_favoritesMutex); for (auto &pattern : patterns) { std::vector patternPath; traversePatternTree(*pattern, patternPath, [&, this](pl::ptrn::Pattern &pattern) { @@ -1128,12 +1132,13 @@ namespace hex::plugin::builtin::ui { ImGui::TableHeadersRow(); this->m_showFavoriteStars = false; - if (!this->m_favorites.empty() && !patterns.empty()) { - ImGui::TableNextColumn(); - ImGui::TableNextColumn(); - ImGui::PushID(1); - if (ImGui::TreeNodeEx("hex.builtin.pattern_drawer.favorites"_lang, ImGuiTreeNodeFlags_SpanFullWidth)) { - if (!this->m_favoritesUpdateTask.isRunning()) { + if (!this->m_favoritesUpdateTask.isRunning()) { + + if (!this->m_favorites.empty() && !patterns.empty()) { + ImGui::TableNextColumn(); + ImGui::TableNextColumn(); + ImGui::PushID(1); + if (ImGui::TreeNodeEx("hex.builtin.pattern_drawer.favorites"_lang, ImGuiTreeNodeFlags_SpanFullWidth)) { for (auto &[path, pattern] : this->m_favorites) { if (pattern == nullptr) continue; @@ -1142,27 +1147,22 @@ namespace hex::plugin::builtin::ui { this->draw(*pattern); ImGui::PopID(); } - } else { - ImGui::TableNextRow(); - ImGui::TableNextColumn(); - ImGui::TableNextColumn(); - ImGui::TextSpinner("hex.builtin.pattern_drawer.updating"_lang); + + ImGui::TreePop(); } - - ImGui::TreePop(); + ImGui::PopID(); } - ImGui::PopID(); - } - this->m_showFavoriteStars = true; + this->m_showFavoriteStars = true; - int id = 2; - for (auto &pattern : this->m_sortedPatterns) { - ImGui::PushID(id); - this->draw(*pattern); - ImGui::PopID(); + int id = 2; + for (auto &pattern : this->m_sortedPatterns) { + ImGui::PushID(id); + this->draw(*pattern); + ImGui::PopID(); - id += 1; + id += 1; + } } ImGui::EndTable(); @@ -1178,6 +1178,9 @@ namespace hex::plugin::builtin::ui { this->m_lastVisualizerError.clear(); this->m_currPatternPath.clear(); + this->m_favoritesUpdateTask.interrupt(); + + std::scoped_lock lock(s_favoritesMutex); for (auto &[path, pattern] : this->m_favorites) pattern = nullptr; this->m_favoritesUpdated = false;