mirror of
https://github.com/aseprite/aseprite.git
synced 2025-01-06 06:58:15 +00:00
Simplify handling of dithering matrices in extensions to avoid memory leaks
This commit is contained in:
parent
fa54bb1950
commit
7ad1b7b965
@ -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);
|
||||
}
|
||||
|
||||
|
@ -10,15 +10,12 @@
|
||||
#pragma once
|
||||
|
||||
#include "obs/signal.h"
|
||||
#include "render/dithering_matrix.h"
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
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,
|
||||
|
Loading…
Reference in New Issue
Block a user