Use unique_ptr instead of shared_ptr to store the sf::Image used by textures
parent
54770d4971
commit
4b3ba9dfb3
|
@ -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&)>;
|
||||
|
||||
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue