diff --git a/src/app/extensions.cpp b/src/app/extensions.cpp index 6b6a1d5b22..e71527d2b2 100644 --- a/src/app/extensions.cpp +++ b/src/app/extensions.cpp @@ -936,15 +936,15 @@ const render::DitheringMatrix* Extensions::ditheringMatrix(const std::string& ma return nullptr; } -std::vector Extensions::ditheringMatrices() +std::vector Extensions::ditheringMatrices() { - std::vector result; + std::vector result; for (auto ext : m_extensions) { if (!ext->isEnabled()) // Ignore disabled themes continue; - for (auto it : ext->m_ditheringMatrices) - result.push_back(it.second); + for (auto& it : ext->m_ditheringMatrices) + result.push_back(&it.second); } return result; } diff --git a/src/app/extensions.h b/src/app/extensions.h index 1521701425..73171889f6 100644 --- a/src/app/extensions.h +++ b/src/app/extensions.h @@ -222,7 +222,13 @@ namespace app { std::string palettePath(const std::string& palId); ExtensionItems palettes() const; const render::DitheringMatrix* ditheringMatrix(const std::string& matrixId); - std::vector ditheringMatrices(); + + // The returned collection can be used temporarily while + // extensions are not installed/uninstalled. Each element is + // pointing to the real matrix info owned by extensions, this is + // needed to cache the matrix because it is lazy loaded from an + // image file. These pointers cannot be deleted. + std::vector ditheringMatrices(); obs::signal NewExtension; obs::signal KeysChange; diff --git a/src/app/ui/context_bar.cpp b/src/app/ui/context_bar.cpp index 4137c39b93..82eae972fa 100644 --- a/src/app/ui/context_bar.cpp +++ b/src/app/ui/context_bar.cpp @@ -1260,9 +1260,9 @@ class ContextBar::DynamicsField : public ButtonSet bool found = false; auto ditheringMatrices = App::instance() ->extensions().ditheringMatrices(); - for (const auto& it : ditheringMatrices) { - if (it.name() == dynaPref.matrixName()) { - m_dynamics.ditheringMatrix = it.matrix(); + for (const auto* it : ditheringMatrices) { + if (it->name() == dynaPref.matrixName()) { + m_dynamics.ditheringMatrix = it->matrix(); found = true; break; } diff --git a/src/app/ui/dithering_selector.cpp b/src/app/ui/dithering_selector.cpp index f5158b0c47..96bf24fbd4 100644 --- a/src/app/ui/dithering_selector.cpp +++ b/src/app/ui/dithering_selector.cpp @@ -1,5 +1,5 @@ // Aseprite -// Copyright (C) 2019-2023 Igara Studio S.A. +// Copyright (C) 2019-2024 Igara Studio S.A. // Copyright (C) 2017 David Capello // // This program is distributed under the terms of @@ -217,25 +217,25 @@ void DitheringSelector::regenerate(int selectedItemIndex) addItem(new DitherItem(render::DitheringAlgorithm::None, render::DitheringMatrix(), Strings::dithering_selector_no_dithering())); - for (const auto& it : ditheringMatrices) { + for (const auto* it : ditheringMatrices) { try { addItem(new DitherItem( render::DitheringAlgorithm::Ordered, - it.matrix(), - Strings::dithering_selector_ordered_dithering() + it.name())); + it->matrix(), + Strings::dithering_selector_ordered_dithering() + it->name())); } catch (const std::exception& e) { LOG(ERROR, "%s\n", e.what()); Console::showException(e); } } - for (const auto& it : ditheringMatrices) { + for (const auto* it : ditheringMatrices) { try { addItem( new DitherItem( render::DitheringAlgorithm::Old, - it.matrix(), - Strings::dithering_selector_old_dithering() + it.name())); + it->matrix(), + Strings::dithering_selector_old_dithering() + it->name())); } catch (const std::exception& e) { LOG(ERROR, "%s\n", e.what()); @@ -251,9 +251,9 @@ void DitheringSelector::regenerate(int selectedItemIndex) case SelectMatrix: addItem(new DitherItem(render::DitheringMatrix(), Strings::dithering_selector_no_dithering())); - for (auto& it : ditheringMatrices) { + for (const auto* it : ditheringMatrices) { try { - addItem(new DitherItem(it.matrix(), it.name())); + addItem(new DitherItem(it->matrix(), it->name())); } catch (const std::exception& e) { LOG(ERROR, "%s\n", e.what());