From f084bc41479c72fc0821e03f23745f2f46f6df38 Mon Sep 17 00:00:00 2001 From: WerWolv Date: Thu, 28 Mar 2024 22:20:35 +0100 Subject: [PATCH] fix: View registers causing crashes when being deleted --- .../content/providers/view_provider.hpp | 27 +++++++++++-------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/plugins/builtin/include/content/providers/view_provider.hpp b/plugins/builtin/include/content/providers/view_provider.hpp index 94d93b102..bd2598250 100644 --- a/plugins/builtin/include/content/providers/view_provider.hpp +++ b/plugins/builtin/include/content/providers/view_provider.hpp @@ -9,15 +9,8 @@ namespace hex::plugin::builtin { class ViewProvider : public hex::prv::Provider { public: - explicit ViewProvider() { - EventProviderClosing::subscribe(this, [this](const prv::Provider *provider, bool*) { - if (m_provider == provider) - ImHexApi::Provider::remove(this, false); - }); - } - ~ViewProvider() override { - EventProviderClosing::unsubscribe(this); - } + ViewProvider() = default; + ~ViewProvider() override = default; [[nodiscard]] bool isAvailable() const override { if (m_provider == nullptr) @@ -52,8 +45,20 @@ namespace hex::plugin::builtin { m_provider->save(); } - [[nodiscard]] bool open() override { return m_provider != this; } - void close() override { } + [[nodiscard]] bool open() override { + if (m_provider == this) + return false; + + EventProviderClosing::subscribe(this, [this](const prv::Provider *provider, bool*) { + if (m_provider == provider) + ImHexApi::Provider::remove(this, false); + }); + + return true; + } + void close() override { + EventProviderClosing::unsubscribe(this); + } void resizeRaw(u64 newSize) override { m_size = newSize;