diff --git a/src/app/extensions.cpp b/src/app/extensions.cpp index a19092514..cde81cd99 100644 --- a/src/app/extensions.cpp +++ b/src/app/extensions.cpp @@ -197,19 +197,24 @@ void write_json_file(const std::string& path, const json11::Json& json) ////////////////////////////////////////////////////////////////////// // Extension -const render::DitheringMatrix& Extension::DitheringMatrixInfo::matrix() const +Extension::DitheringMatrixInfo::DitheringMatrixInfo() { - if (!m_matrix) { - m_matrix = new render::DitheringMatrix; - load_dithering_matrix_from_sprite(m_path, *m_matrix); - } - return *m_matrix; } -void Extension::DitheringMatrixInfo::destroyMatrix() +Extension::DitheringMatrixInfo::DitheringMatrixInfo(const std::string& path, + const std::string& name) + : m_path(path) + , m_name(name) { - if (m_matrix) - delete m_matrix; +} + +const render::DitheringMatrix& Extension::DitheringMatrixInfo::matrix() const +{ + if (!m_loaded) { + m_loaded = true; + load_dithering_matrix_from_sprite(m_path, m_matrix); + } + return m_matrix; } Extension::Extension(const std::string& path, @@ -234,9 +239,6 @@ Extension::Extension(const std::string& path, Extension::~Extension() { - // Delete all matrices - for (auto& it : m_ditheringMatrices) - it.second.destroyMatrix(); } void Extension::executeInitActions() @@ -278,7 +280,7 @@ void Extension::addDitheringMatrix(const std::string& id, const std::string& name) { DitheringMatrixInfo info(path, name); - m_ditheringMatrices[id] = info; + m_ditheringMatrices[id] = std::move(info); updateCategory(Category::DitheringMatrices); } diff --git a/src/app/extensions.h b/src/app/extensions.h index 6c96dee30..ab2e7492b 100644 --- a/src/app/extensions.h +++ b/src/app/extensions.h @@ -10,15 +10,12 @@ #pragma once #include "obs/signal.h" +#include "render/dithering_matrix.h" #include #include #include -namespace render { - class DitheringMatrix; -} - namespace app { // Key=theme/palette/etc. id @@ -50,19 +47,18 @@ namespace app { class DitheringMatrixInfo { public: - DitheringMatrixInfo() : m_matrix(nullptr) { } + DitheringMatrixInfo(); DitheringMatrixInfo(const std::string& path, - const std::string& name) - : m_path(path), m_name(name), m_matrix(nullptr) { } + const std::string& name); const std::string& name() const { return m_name; } const render::DitheringMatrix& matrix() const; - void destroyMatrix(); private: std::string m_path; std::string m_name; - mutable render::DitheringMatrix* m_matrix; + mutable render::DitheringMatrix m_matrix; + mutable bool m_loaded = false; }; Extension(const std::string& path,