From 4b3ba9dfb30a53496b27481081a52ee1ddaed51e Mon Sep 17 00:00:00 2001 From: Bruno Van de Velde Date: Thu, 29 Jun 2017 11:38:44 +0200 Subject: [PATCH] Use unique_ptr instead of shared_ptr to store the sf::Image used by textures --- include/TGUI/Texture.hpp | 2 +- include/TGUI/TextureData.hpp | 2 +- src/TGUI/Texture.cpp | 4 ++-- tests/Texture.cpp | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/include/TGUI/Texture.hpp b/include/TGUI/Texture.hpp index 9d5a00d3..3f4191b4 100644 --- a/include/TGUI/Texture.hpp +++ b/include/TGUI/Texture.hpp @@ -41,7 +41,7 @@ namespace tgui public: using CallbackFunc = std::function)>; - using ImageLoaderFunc = std::function(const sf::String&)>; + using ImageLoaderFunc = std::function(const sf::String&)>; using TextureLoaderFunc = std::function(Texture&, const sf::String&, const sf::IntRect&)>; diff --git a/include/TGUI/TextureData.hpp b/include/TGUI/TextureData.hpp index 061f020d..690879c0 100644 --- a/include/TGUI/TextureData.hpp +++ b/include/TGUI/TextureData.hpp @@ -46,7 +46,7 @@ namespace tgui // Used by the Texture class struct TGUI_API TextureData { - std::shared_ptr image; + std::unique_ptr image; sf::Texture texture; sf::IntRect rect; }; diff --git a/src/TGUI/Texture.cpp b/src/TGUI/Texture.cpp index ab15a11c..3c1a59b5 100644 --- a/src/TGUI/Texture.cpp +++ b/src/TGUI/Texture.cpp @@ -34,9 +34,9 @@ namespace tgui { Texture::TextureLoaderFunc Texture::m_textureLoader = &TextureManager::getTexture; - Texture::ImageLoaderFunc Texture::m_imageLoader = [](const sf::String& filename) -> std::shared_ptr + Texture::ImageLoaderFunc Texture::m_imageLoader = [](const sf::String& filename) -> std::unique_ptr { - auto image = std::make_shared(); + auto image = std::make_unique(); if (image->loadFromFile(filename)) return image; else diff --git a/tests/Texture.cpp b/tests/Texture.cpp index f9bde5b7..82c58345 100644 --- a/tests/Texture.cpp +++ b/tests/Texture.cpp @@ -184,7 +184,7 @@ TEST_CASE("[Texture]") unsigned int count = 0; auto oldImageLoader = tgui::Texture::getImageLoader(); - auto func = [&](const sf::String&){ auto image=std::make_shared(); image->create(1,1); count++; return image; }; + auto func = [&](const sf::String&){ auto image=std::make_unique(); image->create(1,1); count++; return image; }; tgui::Texture::setImageLoader(func); REQUIRE_NOTHROW(tgui::Texture{"resources/image.png"}); REQUIRE(count == 1);