From acc77205bba106be4206436e8b5966237ab47395 Mon Sep 17 00:00:00 2001 From: WerWolv Date: Fri, 24 Jan 2025 21:35:38 +0100 Subject: [PATCH] fix: Image visualizer data processor nodes not working Fixes #2081 --- .../data_processor_nodes/other_nodes.cpp | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/plugins/builtin/source/content/data_processor_nodes/other_nodes.cpp b/plugins/builtin/source/content/data_processor_nodes/other_nodes.cpp index 1581d276d..2467e8165 100644 --- a/plugins/builtin/source/content/data_processor_nodes/other_nodes.cpp +++ b/plugins/builtin/source/content/data_processor_nodes/other_nodes.cpp @@ -291,14 +291,14 @@ namespace hex::plugin::builtin { NodeVisualizerImage() : Node("hex.builtin.nodes.visualizer.image.header", { dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Buffer, "hex.builtin.nodes.common.input") }) { } void drawNode() override { - if (!m_texture.has_value()) { + if (!m_texture.isValid() && !m_data.empty()) { m_texture = ImGuiExt::Texture::fromImage(m_data.data(), m_data.size(), ImGuiExt::Texture::Filter::Nearest); } - ImGui::Image(*m_texture, scaled(ImVec2(m_texture->getAspectRatio() * 200, 200))); + ImGui::Image(m_texture, scaled(ImVec2(m_texture.getAspectRatio() * 200, 200))); if (ImGui::IsItemHovered() && ImGui::IsKeyDown(ImGuiKey_LeftShift)) { ImGui::BeginTooltip(); - ImGui::Image(*m_texture, scaled(ImVec2(m_texture->getAspectRatio() * 600, 600))); + ImGui::Image(m_texture, scaled(ImVec2(m_texture.getAspectRatio() * 600, 600))); ImGui::EndTooltip(); } } @@ -307,11 +307,12 @@ namespace hex::plugin::builtin { const auto &rawData = this->getBufferOnInput(0); m_data = rawData; + m_texture = {}; } private: std::vector m_data; - std::optional m_texture; + ImGuiExt::Texture m_texture; }; class NodeVisualizerImageRGBA : public dp::Node { @@ -319,14 +320,14 @@ namespace hex::plugin::builtin { NodeVisualizerImageRGBA() : Node("hex.builtin.nodes.visualizer.image_rgba.header", { dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Buffer, "hex.builtin.nodes.common.input"), dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Integer, "hex.builtin.nodes.common.width"), dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Integer, "hex.builtin.nodes.common.height") }) { } void drawNode() override { - if (!m_texture.has_value()) { + if (!m_texture.isValid() && !m_data.empty()) { m_texture = ImGuiExt::Texture::fromImage(m_data.data(), m_data.size(), ImGuiExt::Texture::Filter::Nearest); } - ImGui::Image(*m_texture, scaled(ImVec2(m_texture->getAspectRatio() * 200, 200))); + ImGui::Image(m_texture, scaled(ImVec2(m_texture.getAspectRatio() * 200, 200))); if (ImGui::IsItemHovered() && ImGui::IsKeyDown(ImGuiKey_LeftShift)) { ImGui::BeginTooltip(); - ImGui::Image(*m_texture, scaled(ImVec2(m_texture->getAspectRatio() * 600, 600))); + ImGui::Image(m_texture, scaled(ImVec2(m_texture.getAspectRatio() * 600, 600))); ImGui::EndTooltip(); } } @@ -343,11 +344,12 @@ namespace hex::plugin::builtin { throwNodeError(hex::format("Image requires at least {} bytes of data, but only {} bytes are available", requiredBytes, rawData.size())); m_data = rawData; + m_texture = {}; } private: std::vector m_data; - std::optional m_texture; + ImGuiExt::Texture m_texture; }; class NodeVisualizerByteDistribution : public dp::Node {