From 6e19ad438e68c2a7cb4b97a198e8fb008ff99880 Mon Sep 17 00:00:00 2001 From: "shewitt.au" Date: Thu, 25 Sep 2025 20:35:45 +1000 Subject: [PATCH 01/11] Initial fix attempt --- .../content/views/view_pattern_editor.hpp | 3 ++- .../content/views/view_pattern_editor.cpp | 21 ++++++++++++++----- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/plugins/builtin/include/content/views/view_pattern_editor.hpp b/plugins/builtin/include/content/views/view_pattern_editor.hpp index 044ebc6f47530..793ce055f4d11 100644 --- a/plugins/builtin/include/content/views/view_pattern_editor.hpp +++ b/plugins/builtin/include/content/views/view_pattern_editor.hpp @@ -233,7 +233,8 @@ namespace hex::plugin::builtin { void registerMenuItems(); void registerHandlers(); - void handleFileChange(prv::Provider *provider); + void fileChangedCallback(prv::Provider *provider, const std::fs::path &path); + void handleFileChange(prv::Provider *provider, const std::fs::path &path); void openPatternFile(bool trackFile); void savePatternToCurrentFile(bool trackFile); diff --git a/plugins/builtin/source/content/views/view_pattern_editor.cpp b/plugins/builtin/source/content/views/view_pattern_editor.cpp index d21ffc721d937..21c35ea058358 100644 --- a/plugins/builtin/source/content/views/view_pattern_editor.cpp +++ b/plugins/builtin/source/content/views/view_pattern_editor.cpp @@ -1593,7 +1593,7 @@ namespace hex::plugin::builtin { m_sourceCode.get(provider) = code; if (trackFile) { m_changeTracker.get(provider) = wolv::io::ChangeTracker(file); - m_changeTracker.get(provider).startTracking([this, provider]{ this->handleFileChange(provider); }); + m_changeTracker.get(provider).startTracking([this, provider, path]{ this->fileChangedCallback(provider, path); }); } m_textHighlighter.m_needsToUpdateColors = false; TaskManager::createBackgroundTask("hex.builtin.task.parsing_pattern", [this, code, provider](auto&) { this->parsePattern(code, provider); }); @@ -2510,7 +2510,17 @@ namespace hex::plugin::builtin { }); } - void ViewPatternEditor::handleFileChange(prv::Provider *provider) { + // WARNING: this function is called from the context of a worker thread! + void ViewPatternEditor::fileChangedCallback(prv::Provider *provider, const std::fs::path &path) { + // Arrange for a call from the UI thread + TaskManager::doLater( + [this, provider, path] { + this->handleFileChange(provider, path); + } + ); + } + + void ViewPatternEditor::handleFileChange(prv::Provider *provider, const std::fs::path &path) { if (m_ignoreNextChangeEvent.get(provider)) { m_ignoreNextChangeEvent.get(provider) = false; return; @@ -2521,9 +2531,10 @@ namespace hex::plugin::builtin { } m_changeEventAcknowledgementPending.get(provider) = true; - hex::ui::BannerButton::open(ICON_VS_INFO, "hex.builtin.provider.file.reload_changes", ImColor(66, 104, 135), "hex.builtin.provider.file.reload_changes.reload", [this, provider] { - m_changeEventAcknowledgementPending.get(provider) = false; + hex::ui::BannerButton::open(ICON_VS_INFO, "hex.builtin.provider.file.reload_changes", ImColor(66, 104, 135), "hex.builtin.provider.file.reload_changes.reload", [this, provider, path] { + loadPatternFile(path, provider, true); }); + m_changeEventAcknowledgementPending.get(provider) = false; } void ViewPatternEditor::openPatternFile(bool trackFile) { @@ -2593,7 +2604,7 @@ namespace hex::plugin::builtin { if (trackFile) { m_changeTracker.get(provider) = wolv::io::ChangeTracker(file); - m_changeTracker.get(provider).startTracking([this, provider]{ this->handleFileChange(provider); }); + m_changeTracker.get(provider).startTracking([this, provider, path]{ this->fileChangedCallback(provider, path); }); m_ignoreNextChangeEvent.get(provider) = true; } } From 3f0ad9f1e1056f945bf6ce2f544ad637907d38f6 Mon Sep 17 00:00:00 2001 From: "shewitt.au" Date: Thu, 25 Sep 2025 20:50:48 +1000 Subject: [PATCH 02/11] Make pattern file reload work. Make file provider reload safe --- .../include/content/providers/file_provider.hpp | 2 ++ .../source/content/providers/file_provider.cpp | 12 +++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/plugins/builtin/include/content/providers/file_provider.hpp b/plugins/builtin/include/content/providers/file_provider.hpp index b8d0610335079..6b93c3135a3f9 100644 --- a/plugins/builtin/include/content/providers/file_provider.hpp +++ b/plugins/builtin/include/content/providers/file_provider.hpp @@ -63,6 +63,8 @@ namespace hex::plugin::builtin { void convertToDirectAccess(); private: + + void fileChangedCallback(); void handleFileChange(); bool open(bool memoryMapped); diff --git a/plugins/builtin/source/content/providers/file_provider.cpp b/plugins/builtin/source/content/providers/file_provider.cpp index ff8104edcedb8..a2655e928acaf 100644 --- a/plugins/builtin/source/content/providers/file_provider.cpp +++ b/plugins/builtin/source/content/providers/file_provider.cpp @@ -272,7 +272,7 @@ namespace hex::plugin::builtin { m_data = m_file.readVectorAtomic(0x00, m_fileSize); if (!m_data.empty()) { m_changeTracker = wolv::io::ChangeTracker(m_file); - m_changeTracker.startTracking([this]{ this->handleFileChange(); }); + m_changeTracker.startTracking([this]{ this->fileChangedCallback(); }); m_file.close(); m_loadedIntoMemory = true; } @@ -359,6 +359,16 @@ namespace hex::plugin::builtin { this->open(true); } + // WARNING: this function is called from the context of a worker thread! + void FileProvider::fileChangedCallback() { + // Arrange for a call from the UI thread + TaskManager::doLater( + [this] { + this->handleFileChange(); + } + ); + } + void FileProvider::handleFileChange() { if (m_ignoreNextChangeEvent) { m_ignoreNextChangeEvent = false; From 89982180e8ee10063ff311879c68e97b0e1fc49d Mon Sep 17 00:00:00 2001 From: "shewitt.au" Date: Thu, 25 Sep 2025 22:52:21 +1000 Subject: [PATCH 03/11] Fix formatting --- plugins/builtin/source/content/providers/file_provider.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/builtin/source/content/providers/file_provider.cpp b/plugins/builtin/source/content/providers/file_provider.cpp index a2655e928acaf..e72d512c671c6 100644 --- a/plugins/builtin/source/content/providers/file_provider.cpp +++ b/plugins/builtin/source/content/providers/file_provider.cpp @@ -359,7 +359,7 @@ namespace hex::plugin::builtin { this->open(true); } - // WARNING: this function is called from the context of a worker thread! + // WARNING: this function is called from the context of a worker thread! void FileProvider::fileChangedCallback() { // Arrange for a call from the UI thread TaskManager::doLater( From 382cfd1cac7aa1df78f854c17db1a45a65e4653f Mon Sep 17 00:00:00 2001 From: "shewitt.au" Date: Thu, 25 Sep 2025 22:52:21 +1000 Subject: [PATCH 04/11] Fix formatting --- plugins/builtin/source/content/providers/file_provider.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/builtin/source/content/providers/file_provider.cpp b/plugins/builtin/source/content/providers/file_provider.cpp index a2655e928acaf..e72d512c671c6 100644 --- a/plugins/builtin/source/content/providers/file_provider.cpp +++ b/plugins/builtin/source/content/providers/file_provider.cpp @@ -359,7 +359,7 @@ namespace hex::plugin::builtin { this->open(true); } - // WARNING: this function is called from the context of a worker thread! + // WARNING: this function is called from the context of a worker thread! void FileProvider::fileChangedCallback() { // Arrange for a call from the UI thread TaskManager::doLater( From 99b7452ef6a56e797a3115dffd8ee29c155e6f1e Mon Sep 17 00:00:00 2001 From: "shewitt.au" Date: Thu, 25 Sep 2025 22:52:21 +1000 Subject: [PATCH 05/11] Fix formatting --- plugins/builtin/include/content/providers/file_provider.hpp | 1 - plugins/builtin/source/content/providers/file_provider.cpp | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/plugins/builtin/include/content/providers/file_provider.hpp b/plugins/builtin/include/content/providers/file_provider.hpp index 6b93c3135a3f9..9dd4db8af6f24 100644 --- a/plugins/builtin/include/content/providers/file_provider.hpp +++ b/plugins/builtin/include/content/providers/file_provider.hpp @@ -63,7 +63,6 @@ namespace hex::plugin::builtin { void convertToDirectAccess(); private: - void fileChangedCallback(); void handleFileChange(); diff --git a/plugins/builtin/source/content/providers/file_provider.cpp b/plugins/builtin/source/content/providers/file_provider.cpp index a2655e928acaf..e72d512c671c6 100644 --- a/plugins/builtin/source/content/providers/file_provider.cpp +++ b/plugins/builtin/source/content/providers/file_provider.cpp @@ -359,7 +359,7 @@ namespace hex::plugin::builtin { this->open(true); } - // WARNING: this function is called from the context of a worker thread! + // WARNING: this function is called from the context of a worker thread! void FileProvider::fileChangedCallback() { // Arrange for a call from the UI thread TaskManager::doLater( From a76eae2c11d2249a7ab6c938cab0dcd8fc750b22 Mon Sep 17 00:00:00 2001 From: WerWolv Date: Thu, 25 Sep 2025 18:01:53 +0200 Subject: [PATCH 06/11] build: Updated libwolv --- lib/external/libwolv | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/external/libwolv b/lib/external/libwolv index 4eeaba844c493..6c36d9db34ece 160000 --- a/lib/external/libwolv +++ b/lib/external/libwolv @@ -1 +1 @@ -Subproject commit 4eeaba844c4931f69fb9867ed5e3e090640e9fb4 +Subproject commit 6c36d9db34ece138dabdebb08974bd1b5a8c3774 From 3eacdc7621e7a71e23c187fa436eea12fe357c8c Mon Sep 17 00:00:00 2001 From: "shewitt.au" Date: Thu, 25 Sep 2025 20:35:45 +1000 Subject: [PATCH 07/11] Initial fix attempt --- .../content/views/view_pattern_editor.hpp | 3 ++- .../content/views/view_pattern_editor.cpp | 21 ++++++++++++++----- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/plugins/builtin/include/content/views/view_pattern_editor.hpp b/plugins/builtin/include/content/views/view_pattern_editor.hpp index 044ebc6f47530..793ce055f4d11 100644 --- a/plugins/builtin/include/content/views/view_pattern_editor.hpp +++ b/plugins/builtin/include/content/views/view_pattern_editor.hpp @@ -233,7 +233,8 @@ namespace hex::plugin::builtin { void registerMenuItems(); void registerHandlers(); - void handleFileChange(prv::Provider *provider); + void fileChangedCallback(prv::Provider *provider, const std::fs::path &path); + void handleFileChange(prv::Provider *provider, const std::fs::path &path); void openPatternFile(bool trackFile); void savePatternToCurrentFile(bool trackFile); diff --git a/plugins/builtin/source/content/views/view_pattern_editor.cpp b/plugins/builtin/source/content/views/view_pattern_editor.cpp index d21ffc721d937..21c35ea058358 100644 --- a/plugins/builtin/source/content/views/view_pattern_editor.cpp +++ b/plugins/builtin/source/content/views/view_pattern_editor.cpp @@ -1593,7 +1593,7 @@ namespace hex::plugin::builtin { m_sourceCode.get(provider) = code; if (trackFile) { m_changeTracker.get(provider) = wolv::io::ChangeTracker(file); - m_changeTracker.get(provider).startTracking([this, provider]{ this->handleFileChange(provider); }); + m_changeTracker.get(provider).startTracking([this, provider, path]{ this->fileChangedCallback(provider, path); }); } m_textHighlighter.m_needsToUpdateColors = false; TaskManager::createBackgroundTask("hex.builtin.task.parsing_pattern", [this, code, provider](auto&) { this->parsePattern(code, provider); }); @@ -2510,7 +2510,17 @@ namespace hex::plugin::builtin { }); } - void ViewPatternEditor::handleFileChange(prv::Provider *provider) { + // WARNING: this function is called from the context of a worker thread! + void ViewPatternEditor::fileChangedCallback(prv::Provider *provider, const std::fs::path &path) { + // Arrange for a call from the UI thread + TaskManager::doLater( + [this, provider, path] { + this->handleFileChange(provider, path); + } + ); + } + + void ViewPatternEditor::handleFileChange(prv::Provider *provider, const std::fs::path &path) { if (m_ignoreNextChangeEvent.get(provider)) { m_ignoreNextChangeEvent.get(provider) = false; return; @@ -2521,9 +2531,10 @@ namespace hex::plugin::builtin { } m_changeEventAcknowledgementPending.get(provider) = true; - hex::ui::BannerButton::open(ICON_VS_INFO, "hex.builtin.provider.file.reload_changes", ImColor(66, 104, 135), "hex.builtin.provider.file.reload_changes.reload", [this, provider] { - m_changeEventAcknowledgementPending.get(provider) = false; + hex::ui::BannerButton::open(ICON_VS_INFO, "hex.builtin.provider.file.reload_changes", ImColor(66, 104, 135), "hex.builtin.provider.file.reload_changes.reload", [this, provider, path] { + loadPatternFile(path, provider, true); }); + m_changeEventAcknowledgementPending.get(provider) = false; } void ViewPatternEditor::openPatternFile(bool trackFile) { @@ -2593,7 +2604,7 @@ namespace hex::plugin::builtin { if (trackFile) { m_changeTracker.get(provider) = wolv::io::ChangeTracker(file); - m_changeTracker.get(provider).startTracking([this, provider]{ this->handleFileChange(provider); }); + m_changeTracker.get(provider).startTracking([this, provider, path]{ this->fileChangedCallback(provider, path); }); m_ignoreNextChangeEvent.get(provider) = true; } } From 70fd54fedb46ddc8a9fd73e5e1e5badb7add1dd3 Mon Sep 17 00:00:00 2001 From: "shewitt.au" Date: Thu, 25 Sep 2025 20:50:48 +1000 Subject: [PATCH 08/11] Make pattern file reload work. Make file provider reload safe --- .../include/content/providers/file_provider.hpp | 2 ++ .../source/content/providers/file_provider.cpp | 12 +++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/plugins/builtin/include/content/providers/file_provider.hpp b/plugins/builtin/include/content/providers/file_provider.hpp index b8d0610335079..6b93c3135a3f9 100644 --- a/plugins/builtin/include/content/providers/file_provider.hpp +++ b/plugins/builtin/include/content/providers/file_provider.hpp @@ -63,6 +63,8 @@ namespace hex::plugin::builtin { void convertToDirectAccess(); private: + + void fileChangedCallback(); void handleFileChange(); bool open(bool memoryMapped); diff --git a/plugins/builtin/source/content/providers/file_provider.cpp b/plugins/builtin/source/content/providers/file_provider.cpp index ff8104edcedb8..a2655e928acaf 100644 --- a/plugins/builtin/source/content/providers/file_provider.cpp +++ b/plugins/builtin/source/content/providers/file_provider.cpp @@ -272,7 +272,7 @@ namespace hex::plugin::builtin { m_data = m_file.readVectorAtomic(0x00, m_fileSize); if (!m_data.empty()) { m_changeTracker = wolv::io::ChangeTracker(m_file); - m_changeTracker.startTracking([this]{ this->handleFileChange(); }); + m_changeTracker.startTracking([this]{ this->fileChangedCallback(); }); m_file.close(); m_loadedIntoMemory = true; } @@ -359,6 +359,16 @@ namespace hex::plugin::builtin { this->open(true); } + // WARNING: this function is called from the context of a worker thread! + void FileProvider::fileChangedCallback() { + // Arrange for a call from the UI thread + TaskManager::doLater( + [this] { + this->handleFileChange(); + } + ); + } + void FileProvider::handleFileChange() { if (m_ignoreNextChangeEvent) { m_ignoreNextChangeEvent = false; From fdace6f1b44ef34d011fa8544a09065c32251515 Mon Sep 17 00:00:00 2001 From: "shewitt.au" Date: Thu, 25 Sep 2025 22:52:21 +1000 Subject: [PATCH 09/11] Fix formatting --- plugins/builtin/include/content/providers/file_provider.hpp | 1 - plugins/builtin/source/content/providers/file_provider.cpp | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/plugins/builtin/include/content/providers/file_provider.hpp b/plugins/builtin/include/content/providers/file_provider.hpp index 6b93c3135a3f9..9dd4db8af6f24 100644 --- a/plugins/builtin/include/content/providers/file_provider.hpp +++ b/plugins/builtin/include/content/providers/file_provider.hpp @@ -63,7 +63,6 @@ namespace hex::plugin::builtin { void convertToDirectAccess(); private: - void fileChangedCallback(); void handleFileChange(); diff --git a/plugins/builtin/source/content/providers/file_provider.cpp b/plugins/builtin/source/content/providers/file_provider.cpp index a2655e928acaf..e72d512c671c6 100644 --- a/plugins/builtin/source/content/providers/file_provider.cpp +++ b/plugins/builtin/source/content/providers/file_provider.cpp @@ -359,7 +359,7 @@ namespace hex::plugin::builtin { this->open(true); } - // WARNING: this function is called from the context of a worker thread! + // WARNING: this function is called from the context of a worker thread! void FileProvider::fileChangedCallback() { // Arrange for a call from the UI thread TaskManager::doLater( From 6e6188ce90ade62764123fccfc732b2f2451d135 Mon Sep 17 00:00:00 2001 From: "shewitt.au" Date: Fri, 26 Sep 2025 03:10:25 +1000 Subject: [PATCH 10/11] Fix formatting --- plugins/builtin/source/content/providers/file_provider.cpp | 6 +----- .../builtin/source/content/views/view_pattern_editor.cpp | 5 +---- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/plugins/builtin/source/content/providers/file_provider.cpp b/plugins/builtin/source/content/providers/file_provider.cpp index e72d512c671c6..ad4061343e651 100644 --- a/plugins/builtin/source/content/providers/file_provider.cpp +++ b/plugins/builtin/source/content/providers/file_provider.cpp @@ -362,11 +362,7 @@ namespace hex::plugin::builtin { // WARNING: this function is called from the context of a worker thread! void FileProvider::fileChangedCallback() { // Arrange for a call from the UI thread - TaskManager::doLater( - [this] { - this->handleFileChange(); - } - ); + TaskManager::doLater([this]{this->handleFileChange();}); } void FileProvider::handleFileChange() { diff --git a/plugins/builtin/source/content/views/view_pattern_editor.cpp b/plugins/builtin/source/content/views/view_pattern_editor.cpp index 21c35ea058358..1a31ba282ee63 100644 --- a/plugins/builtin/source/content/views/view_pattern_editor.cpp +++ b/plugins/builtin/source/content/views/view_pattern_editor.cpp @@ -2514,10 +2514,7 @@ namespace hex::plugin::builtin { void ViewPatternEditor::fileChangedCallback(prv::Provider *provider, const std::fs::path &path) { // Arrange for a call from the UI thread TaskManager::doLater( - [this, provider, path] { - this->handleFileChange(provider, path); - } - ); + [this, provider, path]{this->handleFileChange(provider, path);}); } void ViewPatternEditor::handleFileChange(prv::Provider *provider, const std::fs::path &path) { From 4ebec70b649f0890cb48898ca1fe306116c0c14c Mon Sep 17 00:00:00 2001 From: "shewitt.au" Date: Fri, 26 Sep 2025 03:10:25 +1000 Subject: [PATCH 11/11] Fix formatting --- plugins/builtin/source/content/providers/file_provider.cpp | 5 +---- plugins/builtin/source/content/views/view_pattern_editor.cpp | 4 +--- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/plugins/builtin/source/content/providers/file_provider.cpp b/plugins/builtin/source/content/providers/file_provider.cpp index e72d512c671c6..055831cc436ab 100644 --- a/plugins/builtin/source/content/providers/file_provider.cpp +++ b/plugins/builtin/source/content/providers/file_provider.cpp @@ -362,10 +362,7 @@ namespace hex::plugin::builtin { // WARNING: this function is called from the context of a worker thread! void FileProvider::fileChangedCallback() { // Arrange for a call from the UI thread - TaskManager::doLater( - [this] { - this->handleFileChange(); - } + TaskManager::doLater([this]{this->handleFileChange();} ); } diff --git a/plugins/builtin/source/content/views/view_pattern_editor.cpp b/plugins/builtin/source/content/views/view_pattern_editor.cpp index 21c35ea058358..b21c15781b107 100644 --- a/plugins/builtin/source/content/views/view_pattern_editor.cpp +++ b/plugins/builtin/source/content/views/view_pattern_editor.cpp @@ -2514,9 +2514,7 @@ namespace hex::plugin::builtin { void ViewPatternEditor::fileChangedCallback(prv::Provider *provider, const std::fs::path &path) { // Arrange for a call from the UI thread TaskManager::doLater( - [this, provider, path] { - this->handleFileChange(provider, path); - } + [this, provider, path]{this->handleFileChange(provider, path);} ); }