Use unique_ptr instead of shared_ptr to store the sf::Image used by textures

0.8
Bruno Van de Velde 2017-06-29 11:38:44 +02:00
parent 54770d4971
commit 4b3ba9dfb3
4 changed files with 5 additions and 5 deletions

View File

@ -41,7 +41,7 @@ namespace tgui
public:
using CallbackFunc = std::function<void(std::shared_ptr<TextureData>)>;
using ImageLoaderFunc = std::function<std::shared_ptr<sf::Image>(const sf::String&)>;
using ImageLoaderFunc = std::function<std::unique_ptr<sf::Image>(const sf::String&)>;
using TextureLoaderFunc = std::function<std::shared_ptr<TextureData>(Texture&, const sf::String&, const sf::IntRect&)>;

View File

@ -46,7 +46,7 @@ namespace tgui
// Used by the Texture class
struct TGUI_API TextureData
{
std::shared_ptr<sf::Image> image;
std::unique_ptr<sf::Image> image;
sf::Texture texture;
sf::IntRect rect;
};

View File

@ -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<sf::Image>
Texture::ImageLoaderFunc Texture::m_imageLoader = [](const sf::String& filename) -> std::unique_ptr<sf::Image>
{
auto image = std::make_shared<sf::Image>();
auto image = std::make_unique<sf::Image>();
if (image->loadFromFile(filename))
return image;
else

View File

@ -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<sf::Image>(); image->create(1,1); count++; return image; };
auto func = [&](const sf::String&){ auto image=std::make_unique<sf::Image>(); image->create(1,1); count++; return image; };
tgui::Texture::setImageLoader(func);
REQUIRE_NOTHROW(tgui::Texture{"resources/image.png"});
REQUIRE(count == 1);